php - 使用 php 运行外部程序

标签 php linux command exec

我有一个 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 的回答,解决方案是添加:

export DISPLAY=:0

命令变为:

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

关于php - 使用 php 运行外部程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5456961/

相关文章:

php - 如何从 PHP 运行 .bat 文件?

php - Htaccess 使用 FastCGI 重写

linux - GCC版本显示冲突

php - 通过 native 调度实现远程Windows Server的Mysql备份

javascript - 如何制作相同大小的缩略图

c - SIGUSR1 终止了进程,尽管我已经阻止了它

linux - Linux 中的 USB 串行驱动程序和设备名称

linux - 如何将 html 发送到 Outlook 14 并使其正确显示?

perl - 如何从 Perl 将输入输入到 Java 命令中?

eclipse - 如何在 eclipse osgi 控制台中调用 "last command"?