从php执行expect脚本。无法正确设置stty

时间:2011-11-12 13:38:23

标签: php expect stty

我有一个执行expect脚本的php脚本。 scpectt通过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...

提前致谢。

1 个答案:

答案 0 :(得分:1)

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

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

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

希望这有帮助。

塞巴斯蒂安

相关问题