![](/img/trans.png)
[英]How to get the output of command executed using child_process in nodejs?
[英]NodeJS forking a bash command using child_process
假設我想運行以下 bash 命令: ./someCommand &
。 當我使用以下節點時:
var execute = require('child_process').exec;
execute(cmd, function (err, out) {
// Do stuff
});
我永遠無法進入回調,我認為問題是因為進程正在等待./someCommand
結束,但我已經嘗試將其分叉!! 我該怎么辦?
如果您不想等待,只需在execute
之后將代碼放在外面。
execute.('-cs -Some Command-', func(err, res){
//Do staff
})
cs - 命令外殼。
您可以使用 spawn 代替 exec。
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.