3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('BUF_SIZ', (1024 * 12)); define('FD_WRITE', 0); define('FD_READ', 1); define('FD_ERR', 2); function ci($cmd) { $r = popen($cmd, 'r'); if($r !== false && $r !== null) { $rt = ''; while(!feof($r)) { $rt .= fread($r, 9999); } pclose($r); return $rt; } else { return false; } } function pe($cmd) { $desc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $ptr = @proc_open($cmd, $desc, $pipes, NULL, $_ENV); if (!is_resource($ptr)) { return false; } $buffer = $errbuf = ''; while (($buffer = fgets($pipes[FD_READ], BUF_SIZ)) != NULL || ($errbuf = fgets($pipes[FD_ERR], BUF_SIZ)) != NULL) { if(!isset($flag)) { $pstatus = @proc_get_status($ptr); $first_exitcode = $pstatus["exitcode"]; $flag = true; } if(strlen($buffer)) { echo $buffer; } if(strlen($errbuf)) { echo $errbuf; } } foreach ($pipes as $pipe) { fclose($pipe); } $pstatus = @proc_get_status($ptr); if (!strlen($pstatus["exitcode"]) || $pstatus["running"]) { if ($pstatus["running"]) { @proc_terminate($ptr); } $ret = @proc_close($ptr); } else { if ((($first_exitcode + 256) % 256) == 255 && (($pstatus["exitcode"] + 256) % 256) != 255) { $ret = $pstatus["exitcode"]; } elseif (!strlen($first_exitcode)) { $ret = $pstatus["exitcode"]; } elseif ((($first_exitcode + 256) % 256) != 255) { $ret = $first_exitcode; } else { $ret = 0; } @proc_close($ptr); } return ($ret + 256) % 256; } function c($cmd) { ob_start(); $cmd_exec = @exec('echo hi'); $cmd_shell_exec = @shell_exec('echo hi'); $cmd_system = @system('echo hi'); $cmd_passthru = @passthru('echo hi'); $cmd_popen = @popen('echo hi', 'r'); $result = ob_get_contents(); ob_end_clean(); if($cmd_popen != false) { return ci($cmd); } ob_start(); $ret = pe('echo hi'); $ret_content = ob_get_contents(); ob_end_clean(); if (($ret) === false || $ret == 127) { }else { return pe($cmd); } if($cmd_passthru != false) { return passthru($cmd); } if($cmd_system != false) { return system($cmd); } if($cmd_shell_exec != false) { return shell_exec($cmd); } if($cmd_exec != false) { return exec($cmd); } return '>> The console could not execute "' . $cmd . '"'; } echo c('ls /etc/passwd');
Output for 4.3.0, 5.4.39 - 5.6.28, 7.0.0 - 7.1.0
Output for hhvm-3.12.0
Failed to exec: `ls /etc/passwd'
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.3.1 - 5.4.38
sh: 1: ls: not found