简体   繁体   中英

child_process.execFile is not working with phantomjs and highcharts-convert.js

I've written a nodejs program for generating highcharts image.It looks like this.

var phantom = require('phantomjs');
var childProcess = require('child_process');
var childArgs = [
    '/usr/bin/Export/highcharts-convert.js',
    '-infile',
    '/usr/bin/infile.json',
    '-outfile',
    '.png',
    '-constr',
    'Chart',
    '-callback',
    '/usr/bin/callback.js'
];
childProcess.execFile(phantom.path, childArgs, null, function(error, stdout, stderr) {
    console.log(error);
    console.log(stdout);
    console.log(stderr);
}

Here, I am getting the stdout as empty string.

But When I execute the same command from terminal, I'm getting the png output on the console. From terminal:

/usr/bin/Export/node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/bin/Export/highcharts-convert.js -infile /usr/bin/infile.json -outfile .png -constr Chart -callback /usr/bin/callback.js

By executing this command on terminal, I'm getting the png output. But when i run the program, i'm getting empty string in the stdout. So is there any additional configuration to be made ?

Thanks in advance..

Setting timeout from 30000 to 0 , worked for me. It takes a bit of time for the phantom script to execute,

childProcess.execFile(phantomjs.path, args, {timeout: 0 }, function(outErr, stdout, stderr) {})

Can you check your timeout value?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM