Akash Babu
Akash Babu

Reputation: 247

is it possible to start phantoms 2 with spawn?

As we know phantomjs 2 isn't officially released, is it possible to download an .exe and use childProcess.spawn('./phantomjs midges.js) to run phantomjs2, it runs via exec but doesn't when I use spawn. I'm trying to avoid using exec since the phantomjs process returns lot of data back and it's a bad practice to use exec in this case and also that I can't run multiple exec's of phantoms

Upvotes: 1

Views: 56

Answers (1)

Vaviloff
Vaviloff

Reputation: 16838

Yes, it's possible. Here's a minimal example, adapted from node's docs.

var spawn = require('child_process').spawn,
    child    = spawn('./phantomjs', ['midges.js']);

child.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

child.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

child.on('close', function (code) {
  console.log('child process exited with code ' + code);
});

Upvotes: 2

Related Questions