0

我有一个要求输入的程序。例如:

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

如何使运行自动化?我怀疑expect为此提供了功能,但以下内容对我不起作用:

#!/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

有人有想法吗?谢谢。

4

2 回答 2

1

尝试以最简单的方式(不要期望):这行得通吗?

program arg1 arg2 <<END
foo
spam
END

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

于 2013-04-11T00:26:31.930 回答
0

spawn "./program arg1 arg2"应该是spawn ./program arg1 arg2

于 2013-04-10T04:47:23.027 回答