按下网页上的按钮时,我必须执行Shell脚本。为此,我使用的是php,因此我在文件test.php中创建了一个按钮
<form method="get" action="buildMaster.php">
<input type="submit" value="Build Master" id="btnMaster">
</form>
当按下按钮时,php buildMaster.php被调用:
<?php
shell_exec('touch /Users/testUser/xxx');
?>
为了进行测试,我只需要触摸一个文件,看看脚本是否被调用,但是什么也没有发生。浏览器(在Mac Lion上为Safari)转到buildMaster.php,但没有任何反应。我究竟做错了什么 ?
好的,找到了。我必须将stderr重定向到stdout。
<?php
$output = shell_exec('touch /Users/testUser/xxx 2>&1');
echo "<pre>$output</pre>";
?>
输出:touch:....权限被拒绝
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句