简体   繁体   English

node.js中产生的进程立即退出

[英]spawned process in node.js exiting immediately

I'm trying to spawn an avconv process inside node.js. 我正在尝试在node.js中生成avconv进程。 It should receive data on stdin and output converted data to stdout 它应该在stdin上接收数据,并将转换后的数据输出到stdout

While the command works in the shell, it immediately closes in node.js and I don't know why: 当命令在外壳中运行时,它立即在node.js中关闭,我不知道为什么:

avconv -v quiet -i pipe:0 -vn -f s16le -acodec pcm_s16le pipe:1

That just works, and in node: 那是可行的,并且在node中:

var a = spawn('avconv', ['-v quiet -i pipe:0 -vn -f s16le -acodec pcm_s16le pipe:1']);

a.on('exit', function(code) {
    pr(code, true);
})

I immediately get a '1' exit code. 我立即得到一个“ 1”退出代码。 Can anyone tell my what's going wrong here? 谁能告诉我这是怎么回事?

You need to separate the argument array yourself: 您需要自己分隔参数数组:

var a = spawn('avconv', ['-v', 'quiet', '-i', 'pipe:0', '-vn', '-f', 's16le', '-acodec', 'pcm_s16le', 'pipe:1']);

The space delimitation you are used to from command line work is provided by your shell (bash, zsh...). Shell会提供您习惯于命令行工作的空格(bash,zsh ...)。 The shell breaks up your command into argument using spaces and lets you say "I want this as a single argument" by adding quotes. Shell使用空格将您的命令分解为参数,并通过添加引号让您说“我希望将此作为单个参数”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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