I try to setup a NodeJS child process with arguments. If I run the child process with node it works fine but if I run in with casperjs instead, it doesn't work. I made sure that casperjs is running properly, with another casperjs script which works fine. Here is my setup:
parent.js
var exec = require('child_process').exec;
exec('node child.js', {
env: {
number: 123
}
}, function(err, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (err !== null) {
console.log('exec error: ' + err);
}
});
parent2.js
var exec = require('child_process').exec;
exec('casperjs child.js', {
env: {
number: 123
}
}, function(err, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (err !== null) {
console.log('exec error: ' + err);
}
});
child.js
var number = process.env.number;
console.log(typeof(number));
number = parseInt(number, 10);
console.log((number));
Output
$ node parent.js
stdout: string
123
stderr:
$ node parent2.js
stdout: Fatal: [Errno 2] No such file or directory; did you install phantomjs?
stderr:
exec error: Error: Command failed:
Why can I not use arguments when running the child process with casperjs?