我对php有问题!我想用php运行一个外部程序。该程序在命令行和linux平台下运行。所以工作一定很顺利。但我试了更多的时间却没办法跑。怎么了!
这是程序的链接:http://www.lalescu.ro/liviu/fet/
这是一个在命令行中运行良好的命令,而不是在php中:

./fet --inputfile=Hopwood.fet --outputdir=out

这是php代码:
<?php
`./fet --inputfile=Hopwood.fet --outputdir=out`
?>

我希望能解决这个问题。
提前谢谢。。
更新我上传可执行程序和Hopwood.fet文件供您尝试。。
这是一个链接:
http://rapidshare.com/files/454756427/fet.tar.gz

最佳答案

尝试在完整路径中执行此操作:

/path/to/installed/fet --inputfile=/path/to/your/Hopwood.fet --outputdir=/path/to/your/out

所以你最终会执行:
exec("/path/to/installed/fet --inputfile=/path/to/your/Hopwood.fet --outputdir=/path/to/your/out");

另外,请确保运行进程能够写入您的/path/to/your/out
更新
为了使事情更清楚,请尝试运行以下命令:
exec("/path/to/installed/fet --inputfile=/path/to/your/Hopwood.fet --outputdir=/path/to/your/out 2> /tmp/fet.error.log", $output, $status);

echo "status: " . $status;
echo "output: " . implode("\n", $output);

if(file_exists("/tmp/fet.error.log"))
{
  echo "Error Log: " . file_get_contents("/tmp/fet.error.log");
}

更新
正如@mkotwd在另一个答案中所说(在尝试调试代码之后,见上文)。问题是因为fet试图访问X服务器。因此,正如@mkotwd answer所说,解决方案是添加:
export DISPLAY=:0

命令变成:
exec("export DISPLAY=:0 && fet --inputfile=Hopwood.fet --outputdir=out");

09-11 02:11
查看更多