Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Question for an Tcl/Expect Script.

Question for an Tcl/Expect Script.

Question for an Tcl/Expect Script.

Hello All,

Hopefully I'm in the correct place for this question, being that Expect is brought to us by the Tcl/Tk programmers I believe...?

I had a question regarding Exect Scripting if someone here could help me.

I am writing a script that will be called from a Bash Script as part of a program I am writing. Depending upon some command line options the
users includes, the Bash script will call this Expect Script I am writing and will open an SSH Session, login, run some commands, then exit...
The question has to do with saving aoutput into a variable.

I have this line, below. Which saves the "expected" output that it finds from a previous "send" command into a variable called "$expectedOutput":

CODE --> Expect

expect {
	-re ".*#.*" { 
		send -- "ps auxww | grep -v grep | grep /path/to/script/bin/myScript\r"
		### This line sends the resulting output from the previous "send" command to the expect_out(buffer)...
		lindex [split $::expect_out(buffer) \n] 0 }
	timeout		{ exit 3 }
	default		{ exit 13 }

expect {
	-re ".*#.*" {
		### This line saves the data stored in the expect_out(buffer) into a variable called "$expectedOutput".
		set extractedOutput $expect_out(buffer)
		puts "extractedOutput = --> \"$extractedOutput\"\n"
	timeout		{ exit 4 }
	default		{ exit 14 }

So basically it is searching for a line that has a "#" (which would signify a command prompt). Next it runs the "ps auxww" command,
then the very next line (beginning with "lindex") will store the output from that "send" command into the "expect_out(buffer)".
In the next "expext { }" section you will see a line that starts with "set". That line will save the output in the variable "$expectOutput".

The problem is that when I save the output into a variable it causes the output of that send command to be suppressed. This can be a bit
of a problem because, if the output is being suppressed then there is nothing being printed to the screen that I would be able to "expect"
to be printed out in order to "send" some more commands.

Does anyone know if there is a work-around for this problem?
Any thoughts or suggestions would be great...!

Thanks in Advance,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close