通过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