如何自动化运行提示用户输入的命令?
问题描述:
我有一个程序要求输入。例如:如何自动化运行提示用户输入的命令?
$ 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
没有人有想法?谢谢。
答
spawn "./program arg1 arg2"
应该是spawn ./program arg1 arg2
。
答
尽量做到最简单的方式(无需指望):这是否工作?
program arg1 arg2 <<END
foo
spam
END
(或printf "%s\n" foo spam | program arg1 arg2
)
正确的,我忘了庆典在这里文档。谢谢。 – RNA 2013-04-11 07:08:13