Php 在脚本中运行exec

Php 在脚本中运行exec,php,Php,我有这个: <?php if ($_GET['run']) { # This code will run if ?run=true is set. exec("./check_sample.sh"); } ? <!-- This link will add ?run=true to your URL, myfilename.php?run=true --> <button type="button" onclick="?run=true">Click Me

我有这个:

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("./check_sample.sh");
}
?

<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<button type="button" onclick="?run=true">Click Me!</button>

exec只会给你最后一行。。。您可能想使用passthru

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  passthru("./check_sample.sh");
}
?
如果您需要将输出作为字符串,您可以选择在输出缓冲块中使用或环绕passthru:即:

 ob_start(); 
 /* passthru call */ 
 $data = ob_get_clean();
不输出任何内容。你可以用

非常小心将用户输入传递到外部程序。如果你真的这样做了,请确保你能用它逃脱

有点像这样:

passthru('./check_sample.sh '.escapeshellarg($your_user_input));

只捕获最后一行,似乎您最好使用变量来捕获它。请参阅手册。其他选择是,,,您可以通过PHP手册找到合适的方法。

是否有任何方法可以做到这一点,而无需使用shell脚本/向其传递参数?在没有正确转义输入的情况下使用shell命令可能会导致严重的安全漏洞。实际上这并没有帮助。我写的是这样的:点击我!当我执行脚本时,屏幕上仍然没有显示任何内容
passthru('./check_sample.sh '.escapeshellarg($your_user_input));