【问题标题】:Executing expect script from php. Can't get the stty settings right从 php 执行期望脚本。无法正确设置 stty
【发布时间】:2023-03-05 07:57:01
【问题描述】:

我有一个执行期望脚本的 php 脚本。 Expect scipt 通过 telnet 远程连接到另一台设备,在那里执行几个命令并返回结果。 php脚本只是将远程设备返回的结果输出到网页上的一种方式。

这是我遇到问题的一行:

stty rows 1000

当我从控制台执行脚本时,一切正常:远程设备返回 1000 行(或者我在 stty 行中指定的任何内容)输出行。 当我从 Web 浏览器执行脚本时,无论我在 stty 行中指定什么,我都会得到 15 行输出。 有谁知道我做错了什么?

以防万一,这里是我正在使用的 scipts:

script.php

<?php echo shell_exec("/path/to/expect_scipt.exp"); ?>

expect_scipt.exp

#!/usr/bin/expect

stty rows 1000
spawn telnet 10.0.0.1
expect "login:"
send "admin\n"
expect "assword:"
send "admin\n"
expect ">"
send "en\n"
expect "assword:"
send "admin\n"
expect "#"
send "show cable modem\n"
expect "#"
exit

这是我测试它们的方法:

我在控制台中运行它:

#su apache
$php script.php
...1000 lines of output...

我打开我的网络浏览器并导航到 script.php

...15 lines of output...

提前致谢。

【问题讨论】:

    标签: php expect stty


    【解决方案1】:

    我在尝试使用 PHP 执行 stty 命令时遇到了类似的问题。

    问题是 apache 用户(www-data)没有权限在那些 /dev/ttyX 特殊文件上执行 stty。

    要解决这个问题,请编辑 /etc/group 并将用户 www-data 添加到拨出组,这是这些文件的默认组。

    希望这会有所帮助。

    塞巴斯蒂安

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 2013-12-01
      • 2018-08-28
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多