2

Need to know if one can send a string of commands to a program.

The program is called Dynamips,

After I launch the program it comes up with "->"

The command I want to send to the terminal is "start R1" and "start R2" you get the picture.

Also want to know if it can sleep for 5 sec and then send the second string.

I did try to echo it but the echo only comes trough when u exit the program.

Any ideas

Regards

1
  • What are you actually trying to do? Aug 26, 2009 at 16:50

2 Answers 2

3

You can use the expect program.

Here is an example script:

spawn /path/to/program/Dynamips
expect -- "->"
send "start R1\r"
expect -- "->" {
  sleep 5
  send "start R2\r"
}
expect eof

You can invoke this with:

expect scriptname
1
  • Important TCL note: The comments are first class language elements. So you can't just comment out any random line of code! If you don't know this, dealing with TCL is a very frustrating experience. Aug 26, 2009 at 17:22
1

Expect is also available as a Perl module, if you are more comfortable in Perl than TCL.

A simple snippet using the Perl Expect module might look like this:

my $bob = Expect->new("bob_program");
$bob->expect(1, "Hullo!");
$bob->send("Hi!\r");
$bob->expect(1, "Bye!");
$bob->send("Later!\r");
$bob->soft_close();

I've worked both with expect/TCL and perl, and I have to say that I prefer the Perl. If you don't already know it, TCL is kind of annoying to pick up.

You must log in to answer this question.