Help capturing output of expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help capturing output of expect script
# 1  
Old 01-23-2014
Help capturing output of expect script

Code:

match_max 500000
set timeout 30

set outcome1 {}
set outcome2 {}
set inputfile C:\\Users\\Administrator\\Desktop\\inputfile.txt
send -i $con "\r";
expect -i $con "Desktop>" {
exp_send "type $inputfile \r"
}
set timeout 30
 
expect {
		"Desktop>" { set outcome $expect_out(0,string);}
		timeout { puts "i am timing out !!!\n"; }
        }

expect "Desktop>"

puts "Outcome1 = $outcome1\n"
puts "Outcome = $outcome\n"
send "exit\r"



I am trying to capture result of
"type C:\Users\Administrator\Desktop\\inputfile.txt "
outcome is returning empty. Smilie

Help is really appreciated.
# 2  
Old 01-23-2014
Quote:
Originally Posted by cityprince143
....
....
I am trying to capture result of
"type C:\Users\Administrator\Desktop\\inputfile.txt "
outcome is returning empty. Smilie

Help is really appreciated.
Show us your input C:\Users\Administrator\Desktop\\inputfile.txt
# 3  
Old 01-23-2014
Input file :-

Image

It is reading correctly, but seems like buffer doesn't copy to "outcome".

I see the buffer filled with the content of the inputfile when i try running it in debug mode.

Code:
expect: set expect_out(0,string) "\u001b[3;32Htype C:\Users\Administrator\D\u001b[3;61Hesktop\inputfile.txt\u001b[5;1HSILENT = YES\u001b[6;1HIGNOREERRORS = ServerNotFound,BadPassword,FailedDependencies\u001b[7;1HSKIPTARGET = NO\u001b[8;1HSOURCEPATH = C:\Users\Administrator\Desktop\swpackages\u001b[9;1H[TARGETS]\u001b[10;1HHOST = 16.186.36.42\u001b[11;1HUID = Administrator\u001b[12;1HPWD = Administrator\u001b[13;1H[END]\u001b[14;1H[TARGETS]\u001b[15;1HHOST = 16.153.135.184\u001b[16;1HUID = Administrator\u001b[17;1HPWD = administrator\u001b[18;1H[END]\u001b[20;1HC:\Users\Administrator\Desktop>"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "\u001b[3;32Htype C:\Users\Administrator\D\u001b[3;61Hesktop\inputfile.txt\u001b[5;1HSILENT = YES\u001b[6;1HIGNOREERRORS = ServerNotFound,BadPassword,FailedDependencies\u001b[7;1HSKIPTARGET = NO\u001b[8;1HSOURCEPATH = C:\Users\Administrator\Desktop\swpackages\u001b[9;1H[TARGETS]\u001b[10;1HHOST = 16.186.36.42\u001b[11;1HUID = Administrator\u001b[12;1HPWD = Administrator\u001b[13;1H[END]\u001b[14;1H[TARGETS]\u001b[15;1HHOST = 16.153.135.184\u001b[16;1HUID = Administrator\u001b[17;1HPWD = administrator\u001b[18;1H[END]\u001b[20;1HC:\Users\Administrator\Desktop>"

* ignore those special character it's bcoz of VT100 conversion.
# 4  
Old 01-23-2014
There are a few things I'm dubious about in that expect script:

no spawn command
prompt not set to Desktop>
$con not defined
function exp_send not defined

Anyway this example works for me and might be a good starting point for you:

Code:
#!/usr/bin/expect -f
match_max 500000
set timeout 30

spawn -noecho cmd

send "PROMPT=Desktop\$G\r"

set outcome1 {}
set outcome2 {}
set inputfile C:\\Users\\Administrator\\Desktop\\inputfile.txt

expect "Desktop>" {
    send "type $inputfile \r"
}
set timeout 30
 
expect {
    -re "\r\n(.*)\r\n.*Desktop>" { set outcome $expect_out(1,string) }
    timeout { puts "i am timing out !!!\n"; }
}

send "exit\r"
expect "Desktop>"

puts "Outcome1 = $outcome1\n"
puts "Outcome = $outcome\n"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture output from expect script

Hi I am new to Expect scripting. I have to connect to a remote server and capture the output. Here I need output of " send "list registered\r"" to be stored in a file. but after execution, /tmp/capture.txt is of 0 byte #!/usr/bin/expect spawn ssh abc@10.10.10.10 -p 5022 expect... (2 Replies)
Discussion started by: bns928
2 Replies

2. Shell Programming and Scripting

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

3. Shell Programming and Scripting

How do I use grep output in an expect script?

Hi, I am using expect to ssh to a remote host and run a program on the remote machine which has a variable runtime. I need to wait until it finishes so I can grab the output file of this program. I am trying to use the output of grep to know when the process finishes. I am trying to capture... (0 Replies)
Discussion started by: vagabond1964
0 Replies

4. Shell Programming and Scripting

Capturing script output and input to log

Hi Is there a way that I can capture a shell script (both output and input) to a log file where I can analyze it? Thanks (6 Replies)
Discussion started by: nimo
6 Replies

5. Shell Programming and Scripting

Capturing output of procedure in variable in shell script

Hi guys I am calling one DB2 stored proc through unix. It is giving me below output. I want to capture the value 150 in one UNIX variable in shell script. Please let me know how I can achieve this. Thanks in advance Value of output parameters -------------------------- Parameter Name :... (5 Replies)
Discussion started by: vnimavat
5 Replies

6. Shell Programming and Scripting

Problem capturing output in TCL script

I have a TCL script that logs into a switch using expect.I send a command "show port-security address" and it returns a table having a large number of rows.I need to capture this output(the table) and store it in a .txt file. I have done this: match_max 5000 set expect_out(buffer) {} set... (0 Replies)
Discussion started by: plasmalightwave
0 Replies

7. Shell Programming and Scripting

Capturing Sybase SP output in Shell Script

Greetings, I need to capture the output of a Sybase stored procedure, inside my shell script( k shell). Based on this output, I need to call another perl script, with input arguments as the result set of the procedure execution. I need to keep looping through and call the perl script, ... (2 Replies)
Discussion started by: rajpreetsidhu
2 Replies

8. Shell Programming and Scripting

capturing line from script output and appending to a file

Hi all, I did some searching in this forum but can't find anything that matches the issue I'm bumping heads with. On a CentOS4/Postfix (and bash everywhere) mail gateway box I run a command periodically to purge the Postfix queue of messages "From:MAILER-DAEMON". This is the one line'r... (6 Replies)
Discussion started by: wally_welder
6 Replies

9. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies

10. Shell Programming and Scripting

capturing output in script

I have the following line in my script: $sftpcmd $rmthost <<COMMANDS>> $sftplog 2>&1 For some reason this is not capturing the errors from sftp, they go to the file attached to the cron entry ie mm hh dd MM * /myscript > cron.out any idea why? digital unix 4.0d (6 Replies)
Discussion started by: MizzGail
6 Replies
Login or Register to Ask a Question