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 pr开发者_开发问答ogram : 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
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");
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.
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).
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");
?>
精彩评论