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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

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

Post 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);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you tried the other execution functions? escapeshellarg()?
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Does it need more slashes?
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Code: Select all

echo 'gpg -e -r Website '.getcwd().'\\GnuPG-test.txt';
note the two backslashes.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
Post Reply