Phantomjs excited process hanging

I am trying to create a node server that creates phantomjs processes to take screenshots. The Grab.js script works fine when executed, and I confirmed that it writes to stdout. The problem is that the node code that spawns the process just hangs. I confirmed that phantomjs is on the way. Does anyone know what could happen here or how can I fix this problem?

Here's the phantom code (grab.js) that displays the page and writes data to standard output:

var page = require('webpage').create(), system = require('system'), fs = require('fs'); var url = system.args[1] || 'google.com'; page.viewportSize = { width: 1024, height: 1200 }; page.open(url, function() { var b64 = page.renderBase64('png'); fs.write('/dev/stdout', b64, 'w'); phantom.exit(); }); 

And here is the node code that spawns the phantom progress and prints the result (hangs):

 var http = require('http'), exec = require('child_process').exec, fs = require('fs'); exec('phantomjs grab.js google.com', function(error, stdout, stderr) { console.log(error, stdout, stderr); }); 
+4
source share
1 answer

I had similar problems with exec, and then I switched to using spawn and worked. According to this article, use spawn when you want the child process to return huge binary data to Node, use exec if you want the child process to return simple status messages. Hth

+1
source

Source: https://habr.com/ru/post/1438066/


All Articles