开发者

Interact with long-running bash script. Automatic inputs when certain outputs appears

echo "yes\yes\oops" | program doesn't work well for a long-running program.

I can think of redirect the output of program to a开发者_如何学编程 file, then use a loop to grep that file until certain output appears. But is there any better idea?


If you prefer/are stuck with bash, perhaps you are looking for expect?

More on that here: http://wiki.tcl.tk/11583


Write a Python, Perl, Ruby or script in another language to interact with the program. In Python you'd use subprocess. In Perl you'd use popen(). Read the program's stdout line-by-line and match against known prompts, replying with the desired response by writing to the program's stdin.

You can do the same in bash, but I personally prefer not to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜