这是我的Expect脚本的一部分。我从PHP页面运行它!
#!/usr/local/bin/expect -f
set timeout 10
set olt [lindex $argv 1]
exp_send "show gpon onu baseinfo $olt\r"
expect {
"*Error*" { send_user "\nInterface Invalida\n"; exit 1 }
"#"
}
puts "$expect_out(buffer)"
当'show'返回几行时,代码工作正常。但当它返回超过20行时,我得到了这样的信息:
can't read "expect_out(buffer)": no such variable
while executing puts "$expect_out(buffer)
此消息仅在我从我的网站运行时出现,如上所述:
$result = exec("./cmd $olt 2>&1", $output, $return_var );
cmd是包含上述期望代码的脚本。
有什么想法吗?
非常感谢!
答案 0 :(得分:0)
我找到了解决方案......数小时搜索......
set NewLineChar "\r"
exp_send "show gpon onu baseinfo $olt\r"
expect {
$NewLineChar { append saida $expect_out(buffer); exp_continue }
"*Error*" { send_user "\nInterface Invalida\n"; exit 1 }
"#"
}
:)