您还需要传递
n符号以使命令生效:
var spawn = require('child_process').spawn, child = spawn('phantomjs');child.stdin.setEncoding('utf-8');child.stdout.pipe(process.stdout);child.stdin.write("console.log('Hello from PhantomJS')n");child.stdin.end(); /// this call seems necessary, at least with plain node.js executable


