user43506 user43506 - 5 years ago 296
Bash Question

Bash Shell Scrpiting, How can I write a script to run a program which ask for input?

I have a program,

, which will need read a parameters file to run, suppose the file called
, so if I use bash

I can run


terminal will show:

please input your parameters file name:

I will type


then the program start to run, and will have some outputs shows on the terminal, like

Please input an int number:

then I will type something like:


then the program will keep running.

I want to write a script, which will automatically read the input and output the terminal content to a

Please help out!

Answer Source

It depends on what the program really does. If it just reads from the standard input, you cat just pipe the input to it and redirect the output to a file:

echo test1 | ./porodry > test1.terminal

If it messes with the terminal, you might need expect.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download