通過MVDS的建議,你可以,我寧願使用proc_open()
寫入STDIN,也不從STDOUT中讀取exec()
/shell_exec()
,以及提供您自己的一組環境變量 - $_ENV
。
一個示例代碼段從我的代碼中提取:
$process = proc_open(
"{$command}",
array(
array('pipe', 'r'),
array('pipe', 'w'),
array('pipe', 'w')
),
$pipes,
NULL,
$_ENV
);
if(is_resource($process)){
fwrite($pipes[0], $string);
fclose($pipes[0]);
$rt = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$rtErr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$exitCode = proc_close($process);
}
瞭解更多:http://php.net/manual/en/function.proc-open.php
任何特別的原因,爲什麼你不能使用PHP或者Python只?即:您可以將python程序翻譯成php – quantumSoup 2010-07-18 17:28:38
我使用PHP生成XML字符串,然後需要將其作爲輸入傳遞給python腳本。就像我在終端窗口中所做的那樣:>>> myprogram myfile.xml ....基本上python腳本接受一個xml文件並處理它以生成一個字體文件。 – ssdesign 2010-07-18 17:37:15
你使用的是什麼Python程序? – quantumSoup 2010-07-18 17:45:11