我有一个执行期望脚本的 php 脚本。Expect scipt 通过 telnet 远程连接到另一台设备,在那里执行几个命令并返回结果。php脚本只是将远程设备返回的结果输出到网页上的一种方式。
这是我遇到问题的一行:
stty rows 1000
当我从控制台执行我的脚本时,一切正常:远程设备返回 1000 行(或者我在 stty 行中指定的任何内容)输出行。当我从 Web 浏览器执行脚本时,无论我在 stty 行中指定什么,我都会得到 15 行输出。有谁知道我做错了什么?
以防万一,这里是我正在使用的 scipts:
脚本.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...
提前致谢。