Re: why no output from exec( $bad_command, $output, $status )?

From: Date: Tue, 20 Jun 2000 22:16:24 +0000
Subject: Re: why no output from exec( $bad_command, $output, $status )?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2383@lists.php.net to get a copy of this message
In article <39494A52.59D9F3DD@valinux.com>, gkeraunen@valinux.com (greg keraunen) wrote: > For example, if I try to exec an command that does not exist, I don't > get the error messages back from the shell. Based on your experience, I'd guess that exec (et al) rebind stdout to come back to PHP, but don't dink around with stderr at all, almost for sure. You might be able to do something with popen() and/or messing with fopen('php:stderr') or whatever that constant is that allows you to read stderr, but it could get kind of funky, I'd guess... And I suppose a feature request to http://bugs.php.net/ to bind stderr to something, and then splat it into stdout if there's an error might be a reasonable thing to think about, but there's probably some Unixy reason why that's a Bad Idea (tm)... Sure would be nice for us newbies though, to get the error message we'd be seeing in the shell if we were logged in as "nobody" and trying to do whatever it is we're trying to do, no matter how dumb it is to an expert. By the way: $status isn't just true/false. It's an integer representing the error number from 'man errno'. You could probably hack in a function to PHP to return that string corresponding to that error number, but since it usually boils down to path or permissions, nobody has bothered yet. That's been on my ToDo list forever, but the odds that I'll ever get around to it are slim to none and Slim's out of town, since I haven't written C code in decades, and still can't train myself not to CD in the middle of a CVS session and screw everything up. Since you really shouldn't be executing arbitrary commands, exec() is usually a set-and-forget function, so once you get it right, it don't really matter about the stderr. Meanwhile, to solve your presumed original problem, give the full path to any command and any file you use for exec(), and make sure "nobody" or whomever is running the PHP process has permission to execute/read/write whatever is invovled in making that command work. Also be sure that doesn't open up a giant security hole to let "nobody" do that. Oh yeah, if your command expects input, you may be able to pipe or echo it in to it, but if it really wants a terminal (eg htpasswd or login or su) then you're SOL, since PHP is not running under a process hooked to a real terminal for security reasons. You'll have to write some sort of shell script thingie to convince the OS you really know what you're doing and it's okay to do that. I'm now 'way into territory I don't understand, so I'll shut up. -- Richard Lynch | If this was worth $$$ to you, buy a CD US Customer Support Director | from one of the artists listed here: Zend Technologies USA | http://www.L-I-E.com/artists.htm http://www.zend.com | (this has nothing to do with Zend, duh!)

« previous php.general (#2383) next »