Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $arg = 'ls';
- /**
- * Execute command
- *
- * @param string $in command
- * @param boolean $re pipes stderr to stdout
- * @return string|bool false
- */
- function cmd($in, $re = false)
- {
- if ($re) $in = $in . ' 2>&1';
- if (function_exists('exec')) {
- @exec($in, $out);
- $out = @join("\n", $out);
- }
- elseif (function_exists('passthru')) {
- ob_start();
- @passthru($in);
- $out = ob_get_clean();
- }
- elseif (function_exists('system')) {
- ob_start();
- @system($in);
- $out = ob_get_clean();
- }
- elseif (function_exists('shell_exec')) {
- $out = shell_exec($in);
- }
- elseif (function_exists('popen') && function_exists('pclose')) {
- if (is_resource($f = @popen($in, 'r'))) {
- $out = '';
- while (!@feof($f))
- $out .= fread($f, 1024);
- pclose($f);
- }
- }
- elseif (function_exists('proc_open')) {
- $pipes = array();
- $process = @proc_open($in . ' 2>&1', [['pipe', 'w'], ['pipe', 'w'], ['pipe', 'w']], $pipes, null);
- $out = @stream_get_contents($pipes[1]);
- }
- else {
- return false;
- }
- return $out;
- }
- echo cmd($arg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement