0

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

asked Mar 28, 2011 at 9:23
12
  • It might help us if you formatted your code so we could see exactly what your trying to run. Commented Mar 28, 2011 at 9:25
  • 1
    are you sure you're running ./fet in the correct subdirectory? Commented Mar 28, 2011 at 9:28
  • all right , i go to edit my question now . Commented Mar 28, 2011 at 9:28
  • As @stillstanding says. So you might like to try using the absolute path to your binary. eg. /usr/bin/local/fet --inputfile=Hopwood.fet --outputdir=out where /usr/bin/local is the directory containing fet Commented Mar 28, 2011 at 9:30
  • @treffynnon i try but no way ! Commented Mar 28, 2011 at 9:33

4 Answers 4

2

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");
answered Mar 28, 2011 at 9:31
Sign up to request clarification or add additional context in comments.

7 Comments

unfortunately , i set the right permission and the whole path but not work !
If the permissions are correct (you need execute on the program and on the input/output dirs and read + execute permission on 'fet' and any resources it requires) and you've checked that the webserver is not running chroot and you've not disabled execution functionality then it will work. Go back and try again.
@symcbean thanks , if you can try the program , i set the link below
nice : this is the output :status: 1output: Error Log: fet: cannot connect to X server
haha! as I though. this problem tell us that your application require X server and that's not usually available on hosting server: en.wikipedia.org/wiki/X_Window_System. I'm sorry, I can't help you anymore, if it's the problem.
|
0

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.

answered Mar 28, 2011 at 9:30

1 Comment

yes i try all this but is not work , the exec command return the 0 int if done , fyi the function return 1 value !!
0

Check php -i | less for:

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

answered Mar 28, 2011 at 9:42

1 Comment

the exec command work right for other program that i try , like resize with inkscape and mkdir command, ls .. the safe mode is off !!
0

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");
?>
answered Mar 28, 2011 at 23:10

2 Comments

You could've mentioned that fet tries to launch a window by default.
@Amey, you should read the whole comment and question and answers ;)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.