RNA
RNA

Reputation: 153311

how to automize the running of a command that prompts for user input?

I have a program that ask for input. For example:

$ program arg1 arg2
Enter the value of arg3: foo
Enter the value of arg4: spam
$

How can I automatize the running? I suspect the expect provide the functionality for that but the following does not work for me:

#!/usr/bin/expect
set timeout 20
spawn "./program arg1 arg2"
expect "Enter the value of arg3:" { send "foo\r" }
expect "Enter the value of arg4:" { send "spam\r" }
interact

Does anyone have ideas? Thanks.

Upvotes: 0

Views: 57

Answers (2)

glenn jackman
glenn jackman

Reputation: 246774

Try doing it the simplest way possible (without expect): Does this work?

program arg1 arg2 <<END
foo
spam
END

(or printf "%s\n" foo spam | program arg1 arg2)

Upvotes: 1

pynexj
pynexj

Reputation: 20688

spawn "./program arg1 arg2" should be spawn ./program arg1 arg2.

Upvotes: 0

Related Questions