Page 1 of 1

exec() not working, (works from the command line)

Posted: Thu Mar 22, 2007 8:19 am
by bokehman
Image

That works and creates an encrypted file but if I try to do it from exec() no file is created and there is no error message. Any ideas?

Code: Select all

echo 'gpg -e -r Website '.getcwd().'\GnuPG-test.txt';
// echos: gpg -e -r Website C:\AppServ5\www\GnuPG-test.txt

exec('gpg -e -r Website '.getcwd().'\GnuPG-test.txt', $result);

echo '<br>'; var_dump($result);

Posted: Thu Mar 22, 2007 8:24 am
by feyd
Have you tried the other execution functions? escapeshellarg()?

Posted: Thu Mar 22, 2007 8:42 am
by bokehman
I tried shell_exec() and passthru() (and system I think, but can't remember now). I tried escapeshellarg() but the input string remains identical. Exec works fine for other arguments though, for example:

Code: Select all

exec('nslookup -type=a forums.devnetwork.net', $result);
var_dump($result);
So it is not a problem with the function.

Posted: Thu Mar 22, 2007 8:45 am
by feyd
Does it need more slashes?

Posted: Thu Mar 22, 2007 8:50 am
by bokehman
I can't see why it would. The echo (which I pasted into the bit of code above without modification) appears to be identical to the aruments that succeed from the command line.

Posted: Thu Mar 22, 2007 10:08 am
by Skara

Code: Select all

echo 'gpg -e -r Website '.getcwd().'\\GnuPG-test.txt';
note the two backslashes.

Posted: Thu Mar 22, 2007 10:17 am
by bokehman
Skara wrote:note the two backslashes.
If that were necessary the error would show in the echo but it doesn't. The only thing an an escape changes is another backslash or a quote. In all other cases it is dealt with as literal. Nevertheless I've tested as you suggest and there is no change.

Posted: Thu Mar 22, 2007 11:47 am
by stereofrog
hi, bokehman ;)

Just as a general tip, always use exec() with stderr redirection (2>&1) to be able to see shell and/or program error output.

Posted: Fri Mar 23, 2007 8:13 am
by bokehman
Thanks for the tip stereofrog, I still haven't found the problem though. I think I'll leave it a few days and come back to it fresh. It's probably something silly.