2012-08-23 48 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); ?> 
相關問題