Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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

2 Answers 2

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->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.

share|improve this answer

Your Answer

 
discard

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