【问题标题】:Use Expect to Fill In a Multiline Prompt使用 Expect 填写多行提示
【发布时间】:2018-07-05 16:51:06
【问题描述】:

我正在尝试使用 Expect 来自动完成一些提示。提示之一,要求用户输入一些文本,然后按 CTR-D 保存文本或按 CTR-C 取消。我不确定,但我假设我试图自动完成的程序正在使用 cat 写入文件(如 cat > file.txt)。

Expect 似乎无法将文本发送到此多行提示符。当我执行时,出现“输入任务描述(^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] 

看来这应该很简单...谢谢!

【问题讨论】:

    标签: linux forms unix expect cat


    【解决方案1】:

    在脚本末尾添加:

    set timeout -1    ;# wait for as long as necessary
    expect eof        ;# for the spawned task to end.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2010-12-17
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多