我正在尝试使用Expect自动完成一些提示。提示之一,要求用户输入一些文本,然后按CTR-D保存文本或按CTR-C取消。我不确定,但是我假设我尝试自动完成的程序正在使用cat写入文件(例如cat> file.txt)。
期望似乎无法将文本发送到此多行提示。当我执行时,出现“输入任务描述(^ D结束文本输入,^ C终止):”行,然后挂起直到超时。有谁知道如何使用Expect做到这一点?
我的脚本:
#!/usr/bin/expect
spawn tasks create
expect "Task assigned to (default=you): "
send "name\r"
expect "Enter a title: "
send "This is a test\r"
expect "Priority (default=wishlist): "
send "high\r"
expect "Comma-separated list of subscribers (default=None): "
send "None\r"
expect "Comma-separated list of task tags (default=None): "
send "None\r"
expect "Enter task description (^D to end text entry, ^C to abort): "
send "Description\r"
send /004
结果:
[name@xxxx.xxx ~/createtasks] ./innerscript.exp
spawn tasks create
Task assigned to (default=you): name
Enter a title: This is a test
Priority (default=wishlist): high
Comma-separated list of subscribers (default=None): None
Comma-separated list of task tags (default=None): None
Enter task description (^D to end text entry, ^C to abort):
[name@xxxx.xxx ~/createtasks]
这看起来应该很简单...谢谢!
答案 0 :(得分:0)
在脚本末尾,添加:
set timeout -1 ;# wait for as long as necessary
expect eof ;# for the spawned task to end.