将参数从PHP传递到Shell

时间:2017-11-09 14:33:45

标签: php shell

我希望通过3个输入字段设置3个变量。单击一个按钮到ShellScript时,应该传递这些变量。 我有以下代码......

PHP:

curl -XPUT 0:9200/river1/doc/_mapping -d '
    {
      "doc": {
        "properties": {
          "fileContent": {
            "type": "object",
            "dynamic": false,
            "properties": {
              "dimension": {
                "type": "object",
                "dynamic": true
              }
            }
          }
        }
      }
    }
'

外壳:

<?php
$min = "20";
$max = "50";
$norm = "70";

$var = shell_exec("action.sh $min $max $norm");
echo $var;
?>

<form>
  Min: <input type="int" name="MIN" value="<?php echo $min;?>">
  <br><br>
  Norm: <input type="int" name="NORM" value="<?php echo $norm;?>">
  <br><br>
  Max: <input type="int" name="MAX" value="<?php echo $max;?>">
  <br><br>
  <input type="submit" name="submit" value="Submit">
</form>

我已经在StackOverflow上阅读了几个QA案例,但实际上并没有帮助。感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

如果您想接收并将其传递给shell,请使用:

<?php

if( !empty( $_POST ) ) {

$min = $_POST['MIN'];
$max = $_POST['MAX'];
$norm = $_POST['NORM'];

echo shell_exec("action.sh $min $max $norm");

}

?>

<form method="POST">
  Min: <input type="number" name="MIN" value="<?php echo $min;?>">
  <br><br>
  Norm: <input type="number" name="NORM" value="<?php echo $norm;?>">
  <br><br>
  Max: <input type="number" name="MAX" value="<?php echo $max;?>">
  <br><br>
  <input type="submit" name="submit" value="Submit">
</form>