D
D
Drm2015-12-22 07:40:29
Node.js
Drm, 2015-12-22 07:40:29

Why is child_process node.js not working?

There is a node file

var spawn = require('child_process').spawn;


var phantom  = spawn('phantomjs', [ 'snapshot.js', 'http://localhost:3000/#/index/', 'index']);

phantom.on('exit', function(code, signal) {
    if (code !== 0) {
        return cb(new Error('Exit code is not 0: ' + code));
    }

    cb();
});

And there is a phantome.js file that is run through the file above.
var page = require('webpage').create();
var system = require('system');
var fs = require('fs');
var url = system.args[1];
var name = system.args[2];

page.open(url, function () {

    fs.write('snapshot/'+name+'.html', page.frameContent, 'w');
    phantom.exit();
});

Both files are in the same directory. if you run the phantom.js file separately, then everything works. But running with a child process I get an error:
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn prg ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
    at child_process.js:1144:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
snakeigor, 2015-12-22
@snakeigor

so after all phantomjs or phantom.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question