exec() troubles

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
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

exec() troubles

Post by The_Anomaly »

Hey guys,


Well, I have my application working wonderfully on my local server, but when I deployed it to the web server, I'm having trouble. Everything is working alright, but the exec function seems to be acting rather stupid. For example:

Code: Select all

 
exec('ls')
 
Returns nothing, but gives me this line in the error log:

Code: Select all

 
sh: /ls: No such file or directory
 
So, I tried using absolute paths,

Code: Select all

exec('/etc/ls')
No difference, same error message. Not sure what to do with this. Every command I try gives me that same error. If you could give me some advice, I'd really appreciate it.

Extra info: Debian server, PHP 5, and all the commands work on command line.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Re: exec() troubles

Post by impulse() »

Try using

Code: Select all

$test = system('ls');
instead. That worked for me whereas exec() only returned the last file in the directory.
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: exec() troubles

Post by The_Anomaly »

I figured out the problem...Safe_Mode is somehow enabled. I can't figure out how to get it out, even though it's disabled in the php.ini. I'd like to get rid of that, but until then I just set up the allowed safe_mode exec path and am using it from there.

However, now on my server, the output redirection is not working. Normally, my command is exec('command 2>&1') which gets my output. However, now that jut puts the following line in my error_log:

Code: Select all

Unable to find a suitable output format for '2>&1'
 
Post Reply