我有一个简单的cmd.php页面来运行使用shell_exec ()输入的命令并显示输出。
当CGI source.
用途: php -q -s -i php args.
我附上了几张照片来说明我的意思。
-v不产生预期的输出

-z显示PHP的用法

有什么想法吗?
编辑
cmd.php
<?php
if ( isset ( $_POST['submit'] ) ) :
$response = shell_exec ( escapeshellcmd ( stripslashes ( $_POST['cmd'] ) ) );
endif;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
pre#response { border: 1px solid #e0e0e0; padding: .5em; }
</style>
<title>Command</title>
</head>
<body>
<form action="cmd.php" method="post">
<p><input type="text" name="cmd" id="cmd" value="<?php echo @htmlspecialchars ( stripslashes ( $_POST['cmd'] ) ); ?>" size="50" />
<button type="submit" name="submit" id="submit" value="Submit">Submit</button>
</p>
</form>
<?php
if ( isset ( $response ) ) :
?>
<pre id="response"><?php
if ( empty ( $response ) ) :
echo 'No response.';
else :
echo htmlspecialchars ( $response );
endif;
?></pre>
<?php
endif;
?>
</body>
</html>发布于 2010-07-12 08:44:51
shell_exec()只返回已写入已执行进程的stdout的字符,而不返回stderr。尝试redirecting stderr to stdout,以便将错误消息存储在$response中。
<?php
define('REDIRECT_STDERR', 1);
if ( isset ( $_POST['submit'] ) ) :
$cmd = escapeshellcmd ( stripslashes ($_POST['cmd']) );
if ( defined('REDIRECT_STDERR') && REDIRECT_STDERR ) :
$cmd .= ' 2>&1';
endif;
$response = shell_exec( $cmd );
endif;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
pre#response { border: 1px solid #e0e0e0; padding: .5em; }
</style>
<title>Command</title>
</head>
<body>
<form action="cmd.php" method="post">
<p>
<input type="text" name="cmd" id="cmd" value="<?php echo @htmlspecialchars ( stripslashes ( $_POST['cmd'] ) ); ?>" size="50" />
<button type="submit" name="submit" id="submit" value="Submit">Submit</button>
</p>
</form>
<?php if ( isset ( $cmd ) ) : ?>
<fieldset><legend><?php echo htmlspecialchars($cmd); ?></legend>
<pre id="response"><?php var_dump($repsonse); ?></pre>
</fieldset>
<?php endif; ?>
</body>
</html>发布于 2012-06-11 11:56:22
请从命令行检查php使用的php.ini。我也有同样的问题(没有来自php命令行的输出),尝试用php.ini替换当前的php.ini--production和命令行php开始正常工作。在最近的php版本(从5.3.10升级到5.4.3)中,似乎修改了一些配置变量。
https://stackoverflow.com/questions/3226730
复制相似问题