简体   繁体   中英

Spawning bash time from Node.js Child Process

I am using child_process.exec() to execute the command time <my application> .

If I run this command in the terminal, my application is timed with Linux's time(1) command. However when executing the same command from a Node.js script child_process.exec(time <my application>); , my application is timed with GNU Time instead.

This is problematic because I need the millisecond precision of time(1) which GNU Time does not provide.

How can I call time(1) from child_process.exec() ? I have tried giving the full path to time(1) instead of just time , however this did not have any effect.

回答我自己的问题:通过将命令包装为以下格式,我成功地实现了对time(1)的使用:child_process.exec( /bin/bash -c "time <my application>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM