我可以从PHP调用nodejs应用程序吗?
我正在尝试做…
<?php $content = `echo 'h1 happy days' | jade`; ?>
但它不会返回任何东西。 其他命令(例如ls
)
我尝试在path中添加jade,在/bin
创build一个链接,而不是在php中。
我究竟做错了什么?
编辑:
从命令行:
bash-3.2$ pwd /Users/billy/test/website-clear bash-3.2$ echo 'h1 happy days' | jade <h1>happy days</h1>bash-3.2$ which jade /bin/jade bash-3.2$
你有两个其他的选项可能适合你:1. proc_open如果你想要更多的控制程度:
$handle = proc_open("jade", array( array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes); fwrite($pipes[0], 'h1 happy days'); fclose($pipes[0]); $result = stream_get_contents($pipes[1]); return $result;
2.使用exec:
exec("echo 'h1 happy days' | jade", $output, $retval); return $output;
确保你有玉的path或使用完整的path玉可执行文件。
使用系统function。 我相信你的外部调用通过操作系统创build它自己的上下文,然后操作系统得到它自己的stdin / stdout / stderr。 做这个,而不是:
<?php $content = system("echo 'h1 happy days' | jade", $retval); ?>