简体   繁体   English

使用shell_exec()

[英]Using shell_exec()

I was wondering if anyone knew how I could use shell_exec() properly. 我想知道是否有人知道如何正确使用shell_exec() I have enabled it in the php.ini file but it doesn't seem to work. 我已经在php.ini文件中启用了它,但它似乎不起作用。

Do I have to log into the shell using a username and password? 我必须使用用户名和密码登录到shell吗?

How would I access something that is on screen -r through shell_exec() ? 我如何通过shell_exec()访问屏幕-r上的内容?

PS I'm trying to run the list command on a Minecraft Server and return the data. PS我正在尝试在Minecraft服务器上运行list命令并返回数据。

No you don't need to log into the shell, the shell will execute as the OS user executing your php commands. 不,您不需要登录shell,shell将作为OS用户执行您的php命令执行。 To begin, first test that you have shell_exec working properly: 首先,首先测试您的shell_exec是否正常工作:

<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

You cannot use shell_exec with interactive commands. 您不能将shell_exec与交互式命令一起使用。 Since you are using screen simply enable the screen log and use file functions to read the screenlog.0 file created in the folder from where the screen was started. 由于您正在使用屏幕,因此只需启用屏幕日志并使用文件功能来读取在启动屏幕的文件夹中创建的screenlog.0文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM