The thing is that the commands are executed as they should. I have tested to give full path "/bin/ls" and that gives the same result. BUT the exit code is -1 still. Not 0 as when running it from command line. Best regards, Peter Lauri www.dwsasia.com - company web site www.lauri.se - personal web site www.carbonfree.org.uk - become Carbon Free -----Original Message----- From: Richard Lynch [mailto:ceo@xxxxxxxxx] Sent: Friday, March 02, 2007 12:29 AM To: Peter Lauri Cc: 'PHP Mailing' Subject: Re: exec from process (deamon) without shell On Thu, March 1, 2007 10:28 am, Peter Lauri wrote: > I have a very complex script that is being called by a running deamon > that > doesn't have any shell. To simplify it I make this script, that is > also > failing: PHP also uses a mini non-shell thingie to run exec. As such, it has no home directory, no $PATH (or is it $path) and not much of anything. Provide the FULL PATH to 'ls' and your test script should work fine. By extension, you need the FULL PATH to everything file-system-related in your real application. You also need to be aware that YOU run as, well, you, and PHP runs as some user defined in httpd.conf (for Apache module) or IUSER_<machinename> for IIS (unless you re-configure) or as, errr, User in httpd.conf for CGI, and then, ummm, for FCGI, you're going to have to research that one. > #/thepathtophp > > <?php > > exec("ls -lrt", $stdout, $exitcode); > > > > if($exitcode!=0) { > > echo "Command ls -lrt could not be executed correctly. > Exit > code: $exitcode\n"; You may also want to dump out implode("\n", $stdout) just in case it has useful messages. You could also consider sending stderr (2) into stdout (1) so that any error messages are captured. See thread from last week on this one. > } else { > > echo "Result:\n"; > > foreach($stdout AS $line) { > > echo $line."\n"; If by some chance performance is an issue (probably not) then you may want to benchmark this end-to-end with 'ab' compared to echo implode("\n", $stdout) I'm not making any prediction either way on this, just noting a simple alternative worth exploring if performance IS an issue. > } > > } > > ?> > > > > This code give the exit code -1 that is equal to that "ls -lrt" could > not be > executed. > > > > Running this from shell give correct result. This invariably indicates a path/permissions difference between you logged in as YOU, and PHP running as some other user in a totally different environment/shell. > Executing it from a web page (thru apache) gives correct result. > > > > But the "shell less" deamon is giving the -1 exit code. > > > > Is exec requiring a shell? Any workaround on this? I will play around, > maybe > something like system() or passthru() will do it, but I haven't tested > that > yet, want to get some feedback first. exec doesn't require a shell. It has some kind of minimal shell already, I think. But it's definitely not the same full-blown shell you use when you login as YOU. (well, probably not, unless you're a shell masochist minimalist. :-) -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php