Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
What are you actually trying to do? – Kyle Brandt Aug 26 '09 at 16:50

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
share|improve this answer
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. – Michael Kohne Aug 26 '09 at 17:22

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->expect(1, "Bye!");

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.