Parse output of spawned node.js child process line by line

后端 未结 6 1876
旧巷少年郎
旧巷少年郎 2020-12-07 21:05

I have a PhantomJS/CasperJS script which I\'m running from within a node.js script using process.spawn(). Since CasperJS doesn\'t support require()

6条回答
  •  天命终不由人
    2020-12-07 21:45

    I found a nicer way to do this with just pure node, which seems to work well:

    const childProcess = require('child_process');
    const readline = require('readline');
    
    const cspr = childProcess.spawn(bin, args);
    
    const rl = readline.createInterface({ input: cspr.stdout });
    rl.on('line', line => /* handle line here */)
    
    

提交回复
热议问题