使用 php 运行外部程序
我的 php 有问题!我想用 php 运行外部程序。该程序在命令行和Linux平台上工作。所以它一定工作得很好。但我尝试了更多时间,但无法运行它。那么怎么了! 这是该程序的链接:http://www.lalescu.ro/liviu/fet/ 这是在命令行中工作正常的命令,而不是在 php 中的情况:
./fet --inputfile=Hopwood.fet --outputdir=out
这是 php 代码:
<?php
`./fet --inputfile=Hopwood.fet --outputdir=out`
?>
我希望解决这个 pb 问题。 预先感谢..
更新我上传了可执行程序和Hopwood.fet文件供您尝试.. 这是一个链接: http://rapidshare.com/files/454756427/fet.tar.gz
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
and this is the php code :
<?php
`./fet --inputfile=Hopwood.fet --outputdir=out`
?>
i hope to solve this pb .
thanks in advance ..
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试以完整路径执行此操作:
这样您最终会执行:
另外,请确保正在运行的进程能够写入您的
/path/to/your/out
UPDATE
为了使事情更清楚,请尝试运行此命令:
UPDATE,
正如 @mkotwd 在另一个答案中所说的那样(在尝试上面的调试代码之后)。问题是因为
fet
尝试访问 X Server。因此,正如 @mkotwd 的回答,解决方案是 add:并且命令变为:
try doing it in full path:
so you'll end up executing:
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:
UPDATE
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:and the command become:
看起来您正在从本地安装运行 fet(基于您发布的 ./fet 命令)。
您需要将 fet 安装位置添加到 PATH 变量中。
在 Linux 系统上,编辑 ~/.bashrc,并添加以下内容:
if /home/mkotwd/fet 是您安装 fet 的位置。
或者,您也可以创建一个目录 ~/bin,将其添加到您的 PATH,如上所述,然后创建一个指向 fet 可执行文件的符号链接 ~/bin/fet。这是推荐的解决方案,因为您不必将将来可能要运行的每个本地命令的目录添加到 PATH 中,您只需为 ~/bin 中的每个可执行文件创建符号链接
您可能还想查看 < a href="http://php.net/manual/en/function.exec.php" rel="nofollow">http://php.net/manual/en/function.exec.php 为用户发布的通话详细信息、安全注意事项以及其他提示谁使用过该命令来执行各种任务。
It looks like you're running fet from a local installation (based on the ./fet command you've posted).
You need to add the location of your fet installation to your PATH variable.
On a linux system, edit your ~/.bashrc, and add the following:
if /home/mkotwd/fet is where you've installed fet.
Alternately, you can also make a directory ~/bin, add it to your PATH as explained above, and create a symlink ~/bin/fet that points to your fet executable. This is the recommended solution because you won't have to add to PATH the directory of every local command you might want to run in the future, you can just create symlinks to each executable in ~/bin
You might also want to check out http://php.net/manual/en/function.exec.php for calling details, security considerations, and miscellaneous tips posted by users who've used the command for various tasks.
检查 php -i | less 为:
它可能是这些安全措施之一,它可以阻止这些关键命令(或两者) 。
Check
php -i | less
for:It might be one of those security measures, which prevents those critical commands (or both).
解决方案是在 : 之前添加此命令,
因此代码变为:
the solution is to add this command before :
so the code become :