如何在使用期望“发送"的同时将输出存储在变量中.命令. [英] How to store output in a variable , while using expect "send" command.
问题描述
大家好,
我在使用send in Expect(tcl)时遇到了一些问题.
问题:
1.在linux机器上,我正在运行一些refelct:使用
获取我所有反射进程的进程ID.
ps -aef | grep反映| grep -v grep | awk''{print $ 2}''
将会返回类似
的内容
19768
19546
10465
2.我想在pf Expect的帮助下做同样的事情,这是我的代码
Hi all,
i am facing some problem while using send in expect (tcl).
problem:
1. in linux machine i am running some process refelct: for getting the process id of all the reflect processes i m using
ps -aef | grep reflect | grep -v grep | awk ''{print $2}''
which will return something like
19768
19546
10465
2. same thing i want to do with the help pf expect , here is my code
proc monitor_server {ip_server} {
source "/cygdrive/e/ncp/pat/pat_config.exp"
set cmd1 {ps -aef | grep reflect | grep -v grep | awk ''{print $2}''}
if {[catch { spawn ssh $ip_server -l root } res]} {
puts $res
return 0
} else {
expect -re "(yes/no)"
send "yes\r"
sleep 1
expect -re "root@$ip_server''s password: "
send "$passwd_testbed\r"
expect -re ".*# " {
send " $cmd1 \r"
expect -re "/\d\n"
puts $expect_out(0,string)
} }
}
该代码正在执行命令,但是当命令执行时,我想将输出放入变量$ expect_out(0,string).
可能是我需要某种模式匹配,还是在发送$ cmd时获得某种变量的结果(我的意思是命令的结果).
因为我是tcl的新手,并且期待.
在此先感谢
tanuj
this code is working up to executing the command, but when the command is getting executed , i want to get the out put in variable $expect_out(0,string).
may be i need some kind on pattern matching for that or is there any other way to get the result in some variable while i send the $cmd (i mean result of the command).
as i am new to tcl and expect.
thanks in advance
tanuj
推荐答案
2}''
将会返回类似
的内容
19768
19546
10465
2.我想在pf Expect的帮助下做同样的事情,这是我的代码
2}''
which will return something like
19768
19546
10465
2. same thing i want to do with the help pf expect , here is my code
proc monitor_server {ip_server} {
source "/cygdrive/e/ncp/pat/pat_config.exp"
set cmd1 {ps -aef | grep reflect | grep -v grep | awk ''{print
2}''} 如果{[catch {spawn ssh
2}''} if {[catch { spawn ssh
ip_server -l root} res]} { 放置
ip_server -l root } res]} { puts
这篇关于如何在使用期望“发送"的同时将输出存储在变量中.命令.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!