Is it possible to run PhantomJS from node.js as a command line argument

后端 未结 3 838
挽巷
挽巷 2020-12-04 18:53

I was recently going to test out running phantomJS from python as a commandline argument, I haven\'t got round to it yet but have seen examples. Because PhantomJS is run fro

3条回答
  •  悲&欢浪女
    2020-12-04 19:27

    As an alternative to Donald Derek's answer, you can use the spawn function. It will allow you to read the child process's output as soon as it's produced rather than the output being buffered and returned to you all at once.

    You can read more about it here.

    An example from the documentation.

    var spawn = require('child_process').spawn,
        ls    = spawn('ls', ['-lh', '/usr']);
    
    ls.stdout.on('data', function (data) {
      console.log('stdout: ' + data);
    });
    
    ls.stderr.on('data', function (data) {
      console.log('stderr: ' + data);
    });
    
    ls.on('close', function (code) {
      console.log('child process exited with code ' + code);
    });
    

提交回复
热议问题