使用php运行外部程序 [英] Run an external program with php

查看:144
本文介绍了使用php运行外部程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php的问题!我想运行一个外部程序与php。这个程序工作在命令行和linux平台。所以它必须工作很好。但我尝试更多的时间,我不能运行它。所以有什么问题!
这是程序的链接: http://www.lalescu.ro/liviu/ fet /
,这是命令行中的命令,而不是在php中的情况:

i have a problem with php ! i want to run an external program with php . this program work in command line and in linux platform . so it must be work just fine . but i try more time and i can't run it . so what's wrong ! this is the link of the program : http://www.lalescu.ro/liviu/fet/ and this is the command which work fine in command line and not the case in php :

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

php代码:

<?php
`./fet --inputfile=Hopwood.fet --outputdir=out`
?>

我希望解决这个pb。
。提前感谢。

i hope to solve this pb . thanks in advance ..

更新我上传可执行程序和Hopwood.fet文件, b $ b这是一个链接:
http://rapidshare.com/files /454756427/fet.tar.gz

Update i upload the executable program and the Hopwood.fet file for you try it .. this is a link : 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 /到/ your / out

Also, make sure running process has ability to write to your /path/to/your/out

UPDATE

为了使事情更清楚,请尝试运行此命令:

To make thing's clearer, please try to run this command:

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");
}

UPDATE

作为@mkotwd告诉另一个答案(尝试调试代码后,上面)。问题是因为 fet 试图访问X Server。所以,作为@mkotwd答案的解决方案是添加:

as @mkotwd told on another answer (after trying debug code, above). The problem is because fet trying to access X Server. So, as @mkotwd answer's the solution is add:

export DISPLAY=:0

,命令变为:

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

这篇关于使用php运行外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆