Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用XAMPP从PHP运行Node.js脚本?_Php_Node.js_Xampp_Phantomjs_Shell Exec - Fatal编程技术网

如何使用XAMPP从PHP运行Node.js脚本?

如何使用XAMPP从PHP运行Node.js脚本?,php,node.js,xampp,phantomjs,shell-exec,Php,Node.js,Xampp,Phantomjs,Shell Exec,我在Windows 7上使用XAMPP运行本地主机,并尝试使用PHPexec函数执行Node.js脚本 我能够成功地使用exec函数运行PhantomJS脚本,但当我尝试对Node.js执行相同的操作时,它不起作用 他是一个正确运行PhantomJS脚本的PHP脚本示例: <?php exec('/phantomjs/bin/phantomjs /phantomjs/scripts/test.js', $output); print_r($output); 如果您能给我提些建议

我在Windows 7上使用XAMPP运行本地主机,并尝试使用PHP
exec
函数执行Node.js脚本

我能够成功地使用
exec
函数运行PhantomJS脚本,但当我尝试对Node.js执行相同的操作时,它不起作用

他是一个正确运行PhantomJS脚本的PHP脚本示例:

<?php

  exec('/phantomjs/bin/phantomjs /phantomjs/scripts/test.js', $output);
  print_r($output);

如果您能给我提些建议,我将不胜感激。谢谢。

我想问题在于路径中的空格,请尝试使用反斜杠字符对其进行转义:
/Program\Files\(x86)…
。您可能还需要双转义,以将反斜杠字符保留在字符串中并发送到shell,但不确定:
/Program\\Files\\\(x86)…
。您的思路是正确的,但最终的效果略有不同。我尝试了1、2、3甚至4个反斜杠来避开空格,但没有成功,但我将完整路径用双引号括起来,效果很好。换言之,以下操作有效:
exec(“/Program Files(x86)/nodejs/node”“/Program Files(x86)/nodejs/test.js”,$output)。如果你想把你的评论变成一个答案,我很乐意接受。谢谢。我想问题是路径中的空格,请尝试使用反斜杠字符转义它们:
/Program\Files\(x86)…
。您可能还需要双转义,以将反斜杠字符保留在字符串中并发送到shell,但不确定:
/Program\\Files\\\(x86)…
。您的思路是正确的,但最终的效果略有不同。我尝试了1、2、3甚至4个反斜杠来避开空格,但没有成功,但我将完整路径用双引号括起来,效果很好。换言之,以下操作有效:
exec(“/Program Files(x86)/nodejs/node”“/Program Files(x86)/nodejs/test.js”,$output)。如果你想把你的评论变成一个答案,我很乐意接受。谢谢
<?php

  exec('/Program Files (x86)/nodejs/node /Program Files (x86)/nodejs/test.js', $output);
  print_r($output);
<?php

  exec('/Program Files (x86)/nodejs/node -v', $output);
  print_r($output);