在nodeJS中生成。我刚刚设法使用它来运行一个bash命令,如下所示。这似乎是非阻塞的,我在浏览器屏幕上得到操作,因为命令通过数据垃圾。
ls = spawn('find',['/'] );
response.writeHead(200, { "Content-Type": "text/plain" });
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
response.write(data);
});
但是我想运行一个带有多个参数的perl脚本
ls = spawn('blah.pl',['--argstring here', '--arg blah'] );
Perl脚本只是为了使用getopts CPAN库获取参数而编写的,它使用CPAN期望库运行一堆东西-如果我有错误,输出到标准输出和标准错误,但我现在最关心的是标准输出。
问题是这没有输出。似乎至少在程序完成执行之前完全阻塞了…在这种情况下,它至少会持续10分钟。
我使用刷出错误吗?
我喜欢节点模块"carrier"
carrier = require "carrier"
childproc = require "child_process"
find = childproc.spawn "find"
find.stdout.setEncoding "utf8"
linereader = carrier.carry find.stdout
linereader.on "line", (line) -> console.log line