从PHP使用linux'dialog'命令 [英] Using linux 'dialog' command from PHP

查看:54
本文介绍了从PHP使用linux'dialog'命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个助手脚本来在服务器上执行各种管理任务,该任务只能从命令行完成,并试图使用对话框"命令来显示消息框,输入,密码提示等,但是,此任务的需求要求我用PHP处理数据.

I'm trying to write a helper script for doing various admin tasks on a server which can only be done from the command line and trying to use the 'dialog' command to display message boxes, inputs, password prompts etc, however, the needs of this task call for me to process the data in PHP.

我在使对话框命令以这种方式工作时遇到问题,无法弄清楚我在做什么错.

I'm having problems getting the dialog command to work in this way and can't figure out what i'm doing wrong.

有一个示例此处

不幸的是,它不起作用.

Unfortunately it doesn't work.

当您在外部应用程序上运行PHP和exec/backtick/system时,IO似乎并没有达到您的预期.

When you run PHP and exec/backtick/system to an external application, the IO doesn't appear to work how you'd expect.

我能得到的最接近的是使用passthru()命令:

The nearest I can get is using the passthru() command:

<?php
  $CMD = "dialog --menu \"Please select\" 10 40 3 backup \"Backup Files\" restore \"Restore Files\"";
  passthru($CMD);
?>

这是PHP允许对话框正确使用STDOUT的唯一方法,其他所有内容均不会显示,但是您可以按回车键来选择一个选项.

This is the only way that PHP will let dialog use the STDOUT properly, anything else results in no display but you can press return to select an option.

我尝试了反引号,exec()和system(),但似乎没有任何作用.

I've tried backticks, exec() and system() but nothing seems to work.

我想知道的是如何从PHP中正确读取STDERR,以将返回值转换为名为$ result的变量.

What I wondered was how to read STDERR properly from within PHP to get the return value into a variable called $result.

我确定其他一些系统管理员以前也必须这样做.

I'm sure some other sysadmins have had to do this before.

我之所以不使用bash的原因是,由于选择而必须执行的一个命令仅产生XML输出,而我无法在bash中有效地对其进行解析.

My reasons for not using bash for this are that one command I have to execute as a result of a selection produces XML output only and I can't parse that effectively in bash.

推荐答案

我认为您不能像这样通过PHP运行ncurses应用程序-也许您应该看一下:

I think you can't run ncurses application through PHP like this - maybe you should take a look at this: http://php.net/manual/de/book.ncurses.php

这篇关于从PHP使用linux'dialog'命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆