gpt4 book ai didi

javascript - 在 Cloud Foundry Node.js 上运行子进程

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:36 33 4
gpt4 key购买 nike

有人尝试过在 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);

但是cloudfoundry.com上的vmc推送,它在vmc日志中给了我错误

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 中执行子进程。

非常感谢!!

最佳答案

看起来 Phantom.js 需要一个名为“phamtom”的二进制文件。我建议看一下 Node 纤维包 - https://github.com/laverdet/node-fibers 。该库不依赖于任何 native 二进制文件,应该可以正常工作。

关于javascript - 在 Cloud Foundry Node.js 上运行子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15056947/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com