note 76687 added to function.exec

From: Date: Thu, 26 Jul 2007 11:24:59 +0000
Subject: note 76687 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-128936@lists.php.net to get a copy of this message
If you're trying to use exec in a script that uses signal SIGCHLD, (i.e. pcntl_signal(SIGCHLD,'sigHandler');) it will return -1 as the exit code of the command (although output is correct!). To resolve this remove the signal handler and add it again after exec. Code will be something like this: ... pcntl_signal(SIGCHLD, 'sigHandler'); ... ... (more codes, functions, classes, etc) ... ... // Now executing the command via exec // Clear the signal pcntl_signal(SIGCHLD, SIG_DFL); // Execute the command exec('mycommand',$output,$retval); // Set the signal back to our handler pcntl_signal(SIGCHLD, 'sigHandler'); // At this point we have correct value of $retval. Same solution can apply to system and passthru as well. ---- Server IP: 216.235.15.211 Probable Submitter: 70.68.46.142 ---- Manual Page -- http://www.php.net/manual/en/function.exec.php Edit -- https://master.php.net/note/edit/76687 Del: integrated -- https://master.php.net/note/delete/76687/integrated Del: useless -- https://master.php.net/note/delete/76687/useless Del: bad code -- https://master.php.net/note/delete/76687/bad+code Del: spam -- https://master.php.net/note/delete/76687/spam Del: non-english -- https://master.php.net/note/delete/76687/non-english Del: in docs -- https://master.php.net/note/delete/76687/in+docs Del: other reasons-- https://master.php.net/note/delete/76687 Reject -- https://master.php.net/note/reject/76687 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128936) next »