Une Bévue
unread,Mar 9, 2012, 7:35:03 AM3/9/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Une Bévue <unbewus...@fai.invalid> wrote:
> reposte un exemple simple :
header('Content-Type: text/html; charset=utf-8');
function my_exec($cmd, $input=''){
$proc=proc_open($cmd, array(0=>array('pipe', 'r'),
1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);
fwrite($pipes[0], $input);
fclose($pipes[0]);
$stdout=stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr=stream_get_contents($pipes[2]);
fclose($pipes[2]);
$rtn=proc_close($proc);
return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn);
}
$std_a= my_exec($cmd);
$stdouts=explode("\n", $std_a['stdout']);
foreach($stdouts as $stdout){
echo $stdout . '<br/>';
}
echo "stderr = " . $std_a['stderr'] . '<br/>';
echo "return = " . $std_a['return'] . '<br/>';
avec $cmd = 'ls -al' ça me donne :
total 19624
drwxr-xr-x 19 yt staff 646 Mar 9 13:15 .
drwxr-xr-x 18 yt staff 612 Mar 9 11:25 ..
-rw-r--r--@ 1 yt staff 6148 Mar 9 11:27 .DS_Store
-rwxr--r-- 1 yt staff 1422 Mar 9 11:15 AB2Html.rb
-rwxr--r-- 1 yt staff 5600 Mar 8 14:01 AB2Xml.rb
[... coupé par moi ...]
drwxr-xr-x 4 yt staff 136 Feb 8 19:51 vcards
-rw-r--r-- 1 yt staff 884 Mar 8 08:22 xsltsaxonproc.php
stderr =
return = 0
avec $cmd = 'totomod' (ie. une commande NON existante), ça me donne :
stderr = sh: totomod: command not found
return = 127
donc, c'est vraiment supeu, ça me donne le code de retour.
encore une fois merci beaucoup pour cette diligente réponse !