php - 使用 PHP exec 执行 Minecraft 命令
问题描述
我正在创建自己的小网站来管理 Minecraft 服务器作为有趣的项目。现在我需要完成的是能够将命令发送到服务器正在运行的屏幕。
我的方法如下:
<?php
if (isset($_POST['startbutton']))
{
exec('sudo screen -S 23971 -X stuff "say hello^M"');
}
?>
<form method="post">
<button type="submit" name="startbutton">Test</button>
</form>
现在,当我在终端本身中执行该命令行时,它工作得很好,但是当我尝试在网站上运行它时,什么也没有发生。如果我只是尝试执行
if (isset($_POST['startbutton']))
{
echo exec('whoami');
}
?>
它也可以正常工作。我不知道我做错了什么。
解决方案
我真的不确定,但试试:
<?php
if (isset($_POST['startbutton']))
{
exec('sudo screen -S 23971 -X stuff "say hello^M"');
exec('YOUR SUDO PSW');
}
?>
<form method="post" action="YOUR PHP PAGE LIKE server.php">
<button type="submit" name="startbutton">Test</button>
</form>
让我知道它是否有效
推荐阅读
- json - 替换令牌任务不适用于我的 .json 文件
- excel - 如何根据另一个工作簿中单元格的值选择行 R1 - RX 并命名标题
- python - 编码分类目标变量 - 更好的方法?
- python - Pandas 将函数应用于列表中的多个列
- google-cloud-platform - 从 GKEPodOperator 返回一个 python 对象
- validation - Terraform 变量验证 Terraform v0.13 与长度和 Substr
- java - 如何在java中添加和合并同一地图的值
- javascript - Javascript,来自 Promise 上的 API emtpy 结果
- python - 如何删除 Django 应用程序中的所有迁移文件
- javascript - 来自 Firebase 身份验证的密码提示和配置文件