user43506 user43506 - 4 years ago 267
Bash Question

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

I have a program,

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

I can run

./porodry


terminal will show:

please input your parameters file name:


I will type

test1


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:

1110


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
test1.terminal
file

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