有没有人尝试在Cloud Foundry 的 node.js上运行子进程?
我有以下代码在本地运行良好:
var port = (process.env.VMC_APP_PORT || 3000),
host = (process.env.VCAP_APP_HOST || 'localhost'),
http = require('http');
var childProcess = require('child_process'),
phantom = require('phantomjs'),
ls;
http.createServer(function(req, res) {
ls = childProcess.exec('phantomjs -h', function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('Child Process STDOUT: '+stdout);
console.log('Child Process STDERR: '+stderr);
});
ls.on('exit', function (code) {
console.log('Child process exited with exit code '+code);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Working...');
res.end();
});
}).listen(port, host);
但是vmc push
在cloudfoundry.com上,它给了我错误vmc logs
Reading logs/stdout.log... OK
Child process exited with exit code 127
Error: Command failed: /bin/sh: phantomjs: not found
at ChildProcess.exithandler (child_process.js:536:15)
at ChildProcess.EventEmitter.emit (events.js:91:17)
at maybeClose (child_process.js:634:16)
at Socket.ChildProcess.spawn.stdin (child_process.js:805:11)
at Socket.EventEmitter.emit (events.js:88:17)
at Socket._destroy.destroyed (net.js:358:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Error code: 127
Signal received: null
Child Process STDOUT:
Child Process STDERR: /bin/sh: phantomjs: not found
Child process exited with exit code 127
Error: Command failed: /bin/sh: phantomjs: not found
at ChildProcess.exithandler (child_process.js:536:15)
at ChildProcess.EventEmitter.emit (events.js:91:17)
at maybeClose (child_process.js:634:16)
at Socket.ChildProcess.spawn.stdin (child_process.js:805:11)
at Socket.EventEmitter.emit (events.js:88:17)
at Socket._destroy.destroyed (net.js:358:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Error code: 127
Signal received: null
Child Process STDOUT:
Child Process STDERR: /bin/sh: phantomjs: not found
然后我还在package.json
下面添加了文件,仍然是同样的错误:
{
"name" : "mytestchildprocesses",
"version" : "0.1.0",
"dependencies" : {
"phantomjs" : "1.8.1-3",
"child_process" : "0.x.x",
"http" : "0.0.0"
}
}
或者,我尝试了其他人将 phantomjs 放在 node.js 上:https ://github.com/sgentle/phantomjs-node 。但是这个选项甚至在我的本地机器上都不起作用(在 Windows 中不能调用 phantomjs.cmd)。
如果你们可以提供帮助,我宁愿想办法在 cloudfoundry.com 中执行子进程。
非常感谢!!