无法在PHP中执行节点模块

时间:2013-08-27 10:34:36

标签: php node.js unix

安装必要的模块后,执行以下命令

azure account -help 

按预期工作。但是,当我使用exec()从PHP内部调用相同的命令时。

exec('azure account -help',$output,$responseCode)

并打印输出,我得

  

$ output:[](空数组)和$ responseCode:8

我尝试使用'node'命令执行模块。实施例

  

节点/usr/lib/node_modules/azure-cli/bin/azure.js account -help

这也适用于命令行,但不适用于PHP的exec。

编辑:使用以下命令重定向stderr:

exec('azure account -help &2>1',$output,$responseCode)

提供以下详细信息:

  

,E === undefined)&& (process.env.HOMEDRIVE === undefined))){throw new Error(,^,Error:HOME not found,无法存储Streamline回调缓存,在Object。(/ usr / local / lib / node_modules / azure-cli) /node_modules/streamline/lib/compiler/compile.js:278:90),在Module._compile(module.js:456:26),在Object.Module._extensions..js(module.js:474:10) ,在Module.load(module.js:356:32),在Function.Module._load(module.js:312:12),在Module.require(module.js:364:17),在require(模块。 js:380:17),在Object。(/usr/local/lib/node_modules/azure-cli/node_modules/streamline/lib/compiler/register.js:28:15),在Module._compile(module.js: 456:26),在Object.Module._extensions..js(module.js:474:10)

我可以尝试进一步调试此内容吗?

2 个答案:

答案 0 :(得分:3)

通过调用exec()并提供HOME env变量来解决问题:

  

exec('HOME = / tmp / azure account -help 2>& 1');

答案 1 :(得分:0)

php不了解节点,因此请确保指定nodejs的完整路径,如

exec('c:/nodejs/node.exe mynode_scripts.js',$retr_err,$retr_val);