开发者

node.js using spawn for perl - stdout line by line

Spawn in nodeJS. I have just about managed to use this to run a bash command as follows. This seems to be pretty much non-blocing and I get action on the browser screen as the command trashes through data.

ls = spawn('find',['/'] );
response.writeHead(200, { "Content-Type": "text/plain" });

ls.stdout.on('data', function (data) {
   console开发者_开发技巧.log('stdout: ' + data);
   response.write(data);
});

But I want to run a perl script with multiple arguments.

ls = spawn('blah.pl',['--argstring here', '--arg blah'] );

Perl script is just written to get arguments using getopts CPAN lib and it using CPAN expect lib to run though a pile of stuff - outputs to stdout and stderr if I have an error but I mostly care about stdout right now.

The thing is this is giving me no output. Seems to be completely blocking at least until the program finishes execution ... and it this case it doesn't at least for 10 mins.

Am I using spawn wrong?


I like the node module "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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜