2012-08-23 36 views
1

我试图做...我可以从PHP调用nodejs应用程序吗?

<?php $content = `echo 'h1 happy days' | jade`; ?> 

但它不会返回任何东西。其他命令(例如ls

我试着在路径中添加了jade,在/bin中创建了一个链接,它在命令行中工作,但不能在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$ 
+0

而这从命令行100%正确工作? – Matchu

+0

@Matchu - 是的,请参阅编辑 –

+0

你试过'| |/bin/jade' – Esailija

回答

1

您有可能会适合你以及其他两个选项: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; 

请确保您有路径中的玉或使用完整路径来执行jade。

0

使用system功能。我相信你的外部调用通过操作系统创建它自己的上下文,然后操作系统得到它自己的stdin/stdout/stderr。做到这一点,而不是:

<?php $content = system("echo 'h1 happy days' | jade", $retval); ?> 
相关问题