-----Original Message----- From: Daevid Vincent [mailto:[EMAIL PROTECTED] Sent: Sunday, June 22, 2003 8:05 PM To: 'Don Read' Subject: RE: [PHP] How do I get the exit code of an external program?
> -----Original Message----- > From: Don Read [mailto:[EMAIL PROTECTED] > Sent: Sunday, June 22, 2003 7:58 PM > To: Daevid Vincent > Cc: PHP Lists > Subject: Re: [PHP] How do I get the exit code of an external program? > > > > On 23-Jun-2003 Daevid Vincent wrote: > > I wish to use Ping to test if some IP addresses are up... > Now I could run > > the command and parse to find various string components like this: > > > > <snip> > > > > So it seems to me there needs to be another PHP function > like exec(), > > shell(), etc. that is the equivillent of the php exit() > function but for > > external programs. One that simply returns the integer exit > code of an > > executed shell program... > > > > > > exec(), system(), & popen()/pclose() will return exit code. > > The manual is your friend. http://us3.php.net/manual/en/function.exec.php string exec ( string command [, array output [, int return_var]]) exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. However, you are correct in that there is the optional parameter that I've never used before. Thanks for pointing that out... http://us3.php.net/manual/en/function.system.php string system ( string command [, int return_var]) system() is just like the C version of the function in that it executes the given command and outputs the result. If a variable is provided as the second argument, then the return status code of the executed command will be written to this variable. The problem is that system want's to dump the output to the screen!!! I need a command that will allow me to execute/system the command "silently" and then *I* can do something based upon the exit code... function active_nMap() { $test = exec("/usr/bin/nmap -sP ".$this->IP); if ( strstr($test,"1 host up") ) $this->active = true; else $this->active = false; return $this->active; } function active_ping() { $test = `ping -n -c 1 -w 1 -q $this->IP`; if ( strstr($test,"100% loss") ) $this->active = false; else $this->active = true; return $this->active; } function active_ping_exit() { //http://us3.php.net/manual/en/function.system.php $test = system("ping -n -c 1 -w 1 -q $this->IP", $code); if ( $code == 0 ) $this->active = true; else $this->active = false; return $this->active; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php