Run an external program with php

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 06:22:06

问题


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


回答1:


try doing it in full path:

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

so you'll end up executing:

exec("/path/to/installed/fet --inputfile=/path/to/your/Hopwood.fet --outputdir=/path/to/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

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

and the command become:

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



回答2:


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:

export PATH=$PATH:/home/mkotwd/fet

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.




回答3:


Check php -i | less for:

  • safe_mode
  • configuration of suhosin, if installed

It might be one of those security measures, which prevents those critical commands (or both).




回答4:


the solution is to add this command before :

export DISPLAY=:0

so the code become :

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


来源:https://stackoverflow.com/questions/5456961/run-an-external-program-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!