javascript - PHP在一个框中实时显示Shell命令输出
问题描述
我有以下代码要求输入然后适用shell.sh $folderPath $bits $group2
而且我想有一个盒子,它可以准确地显示我的脚本的输出,如果我在终端中运行它会是什么样子。
我怎么做?
下面是我的代码。
<?php
if (isset($_GET['folderPath']) && !empty($_GET['folderPath']) && file_exists($_GET['folderPath'])
&& is_dir($_GET['folderPath']) && isset($_GET['bits']) && isset($_GET['group2'])) {
$folderPath = $_GET['folderPath'];
$bits = $_GET['bits'];
$group2 = $_GET['group2'];
$run = shell_exec("shell.sh $folderPath $bits $group2");
echo "shell.sh $folderPath $bits $group2";
var_dump($run);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<form action="">
<label for="folderPath">Folder Path:</label>
<input type="text" id="folderPath" name="folderPath">
<br></br>
<fieldset id="bits">
<p>Please Choose bits: </p>
<input type="radio" value="8bits" name="bits"> 8bits <br>
<input type="radio" value="16bits" name="bits"> 16bits <br>
</fieldset>
<br></br>
<fieldset id="audio-type">
<p>Please Choose Type: </p>
<input type="radio" value="C12" name="group2"> C12 <br>
<input type="radio" value="LR" name="group2"> LR <br>
</fieldset>
<input class = "submitButton" type="submit" value="Submit">
</body>
</html>
解决方案
首先,您需要将表单数据发送到某个地方。在您的情况下,这是您的相同脚本。
<form method="GET" action="path/to/my/script.php">
其次,shell_exec()返回执行命令的输出。您已经编写了代码。
$path = $_GET['folderPath'];
$bits = $_GET['bits'];
$group2 = $_GET['group2'];
$output = shell_exec("shell.sh $path $bits $group2");
第三,在您想要的位置显示输出。
<div><?php print $output; ?></div>
推荐阅读
- python - 如何根据用户提出的问题使用变量进行公式计算
- akka - Actor 的 Akka 邮箱大小的 Codehale 指标?
- r - 在 ggplot2 的 y 轴上插入自定义标签
- json - 如何配置 tsc 以从特定文件夹编译测试规范?
- typescript - 使用索引签名扩展类
- java - LinearLayout 的旋转使其被切断
- android - Kotlin 检查字符串中的单词
- php - 用 Laravel 路由上的 URL 上的对象名称替换对象 ID
- json - 如何创建自定义表单验证器以仅接受 Angular 中的有效 JSON
- angular - Ng-Chart ocultar 数据集