从php执行expect脚本.我无法正确设置样式


Executing expect script from php. Can't get the stty settings right

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

这一行我有问题:

stty rows 1000

当我从控制台中执行脚本时,一切都正常工作:远程设备返回1000(无论我在stty行中指定什么)行输出。当我从web浏览器执行脚本时,无论我在stty行中指定什么,我都会得到15行输出。有人知道我哪里做错了吗?

为了以防万一,下面是我使用的脚本:

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执行stty命令时遇到了类似的问题。

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

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

希望对你有帮助。

塞巴斯蒂安