Zam*_*ezi 9 linux terminal bash
我有一个程序需要我在程序运行时输入数据。想象一下它是这样的:
$ ./program
Hi there. What's your name? Zambezi
What is your quest? To make a program which runs nicely
What is your favourite color? Red
...
Run Code Online (Sandbox Code Playgroud)
现在,我有许多测试输入来运行我的程序。它们都包含以下内容:
Arthur, King of the Britons
To seek the Holy Grail
...
Run Code Online (Sandbox Code Playgroud)
然而,我的一些测试脚本失败了,不幸的是我很难准确地破译它们失败的地方,因为我的终端看起来像这样:
$ ./program < arthur.txt
Hi there. What's your name?What is your quest?What is your favourite color?...
Run Code Online (Sandbox Code Playgroud)
有没有办法我仍然可以stdin通过文件提供输入,但仍然让终端看起来好像我已经输入了所有内容?
如果重要的话,Linux Mint 16 是我的操作系统。
som*_*ser 13
而不是使用输入重定向(./program < arthur.txt),它只是缓冲输入到您的程序,您应该使用工具作为“期望”等待问题并一一发送答案。
#!/usr/bin/expect
log_user 0
spawn ./program
log_user 1
expect {
"*?"
}
send "Arthur, King of the Britons\r"
expect {
"*?"
}
send "To seek the Holy Grail\r"
expect {
"*?"
}
send "...\r"
Run Code Online (Sandbox Code Playgroud)
更好的例子:http : //www.pantz.org/software/expect/expect_examples_and_tips.html
这正是tee用于。
例如:
$ echo foo | tee >( grep bar )
foo
$
Run Code Online (Sandbox Code Playgroud)
这里发生的是 tee 获取 stdin 并将其复制到 stdout 并再次通过管道输出。就像管道的接头一样。
查看联机帮助页 tee(1) 了解更多详细信息。
| 归档时间: |
|
| 查看次数: |
1138 次 |
| 最近记录: |