我有一个头顶 Controller (对某些机器人来说有点像魔杖)插入我的 USB 端口。 我正在尝试在 Linux 上创建一个 Web 服务器,允许用户向机器人发送预加载的代码(因此没有人输入任何内容)。我已将命令嵌入到我试图在 php 文件中执行的脚本文件中。在 web 服务器上按下按钮时,会运行在 php 中执行脚本文件的代码。但是,当我按下按钮时,什么也没有发生。代码不会发送到 Controller ,也不会给出任何错误。 我可以在命令行中毫无问题地运行脚本。但是当我尝试从网络服务器运行它时,什么也没有发生。有什么办法可以解决这个问题吗? 这是 php 文件中的内容
<html>
<body>
<h1><font face="verdana" color="green">SwarmArena</font></h1>
<hr>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type ="text" name = "name"/>. ; <br>
Age: <input type ="text" name="age"/>. ; <br>
New Code: <textarea cols=40 rows=10 name="Newcode">Default text</textar$
<input type = "submit" name="enter" value="Enter" />
<input type = "submit" name="insert" value="insert" />
<input type = "submit" name="select" value="select" />
<input type = "submit" name="sleep" value="sleep" />
<input type = "submit" name="reset" value="reset" />
</form>
</body>
</html>
<?php
if(isset($_POST['sleep'])){
$out = shell_exec('./sleep.sh');
echo "$out";
}
?>
这是 sleep.sh 中的内容
#!/bin/sh
cd kilocmd && ./kcmd -s /dev/ttyUSB0 -c sleep
echo "done";
谢谢
最佳答案
我不知道你是怎么做到的。但是点击按钮它应该提交到一个 php 页面,该页面将使用 exec 和 shell_exec
php 命令运行 shell 脚本。
除此之外还有几种可能会导致问题,例如
- exec and shell_exec are disabled in php.ini
- The path to the executable is wrong. If the script is in the same
directory as the php file, try exec(dirname(__FILE__) .
'/myscript.sh');
关于php - 如何在php中执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39017373/