简体   繁体   English

交互式外壳脚本命令行php

[英]interactive shell script command line php

I am trying to implement a feature on my web application to provide the user the ability to interact with the command line on the server. 我正在尝试在Web应用程序上实现一项功能,以使用户能够与服务器上的命令行进行交互。

The problem is: is it possible to integrate the command line with the web application so any result will be produced can be shown to the user even if the processes is still working in the background and any input can be taken and processed so it will be like -a function. 问题是:是否可以将命令行与Web应用程序集成在一起,从而即使过程仍在后台运行并且可以接受和处理任何输入,也可以将任何结果显示给用户。像-a函数。

I have tried all the exec() shell_exec() i have tried to redirect the result of the interactive command by 2> SomeFile.txt but the output will not be the result of the interactive command 我已经尝试了所有的exec()shell_exec()我都尝试通过2> SomeFile.txt重定向交互式命令的结果,但是输出将不是交互式命令的结果

1.With commands return the output. 1.With命令返回输出。 Use: 采用:

shell_exec — Execute command via shell and return the complete output as a string shell_exec —通过外壳执行命令并以字符串形式返回完整的输出

passthru — Execute an external program and display raw output passthru —执行外部程序并显示原始输出

system — Execute an external program and display the output 系统 —执行外部程序并显示输出

2.With commands not return the output. 2.使用命令不返回输出。 Use: 采用:

system or passthru then check return_var argument and print the output 系统或passthru,然后检查return_var参数并打印输出

system('touch readme.txt', $retval);
if(!$retval){
    print 'Touched file with success';
}

Or 要么

if(!touch('readme.txt', time())){
    print 'Whoops, something went wrong...';
}

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

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