1

我正在尝试做...

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

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

我尝试将翡翠添加到路径中,创建一个/bin可以从命令行工作的链接,但不能在 php.ini 中工作。

我究竟做错了什么?

编辑:

从命令行:

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$ 
4

2 回答 2

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("echo 'h1 happy days' | jade", $output, $retval);
    return $output;

确保路径中有翡翠或使用翡翠可执行文件的完整路径。

于 2012-08-23T20:22:29.603 回答
0

使用系统功能。我相信您的外部调用由操作系统创建它自己的上下文,然后获得它自己的 stdin/stdout/stderr。改为这样做:

<?php $content = system("echo 'h1 happy days' | jade", $retval); ?>
于 2012-08-23T19:36:51.447 回答