2013-04-10 90 views
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 

沒有人有想法?謝謝。

回答

0

spawn "./program arg1 arg2"應該是spawn ./program arg1 arg2

1

儘量做到最簡單的方式(無需指望):這是否工作?

program arg1 arg2 <<END 
foo 
spam 
END 

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

+0

正確的,我忘了慶典在這裏文檔。謝謝。 – RNA 2013-04-11 07:08:13

相關問題