note 94929 modified in function.system by thiago

From: Date: Thu, 03 Dec 2009 11:59:35 +0000
Subject: note 94929 modified in function.system by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163528@lists.php.net to get a copy of this message
If you can't see any output or error from system(), shell_exec() etc, you could try this: <?php 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 ); } var_export(my_exec('echo -e $(</dev/stdin) | wc -l', 'h\\nel\\nlo')); ?> For example, "echo shell_exec('ls');" will get nothing output, "my_exec('ls');" will get "sh: ls: command not found", "my_exec('/bin/ls');" will maybe get "sh: /bin/ls: Permission denied", and the permission may be caused by selinux. --was-- If you can't see any output or error from system(), shell_exec() etc, you could try this: 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 ); } var_export(my_exec('echo -e $(</dev/stdin) | wc -l', 'h\\nel\\nlo')); For example, "echo shell_exec('ls');" will get nothing output, "my_exec('ls');" will get "sh: ls: command not found", "my_exec('/bin/ls');" will maybe get "sh: /bin/ls: Permission denied", and the permission may be caused by selinux. http://php.net/manual/en/function.system.php

« previous php.notes (#163528) next »