不用等待期望脚本中的用户输入 [英] gets not waiting for user input in expect script

查看:86
本文介绍了不用等待期望脚本中的用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行以下期望脚本时,它只是完成运行,而是等待用户输入.有人可以告诉我我在做什么错吗?

When i try to run the following expect script, it just finishes running instead waiting for user input. Could someone tell me what i am doing wrong?

#!/usr/bin/expect
puts -nonewline stdout "Enter device id:"
flush stdout
gets stdin id
puts -nonewline  stdout "Enter device name:"
flush stdout
gets stdin name

推荐答案

Expect更改了Tcl gets命令,以使其不等待标准输入.要在等待时读取一行,您需要执行此操作,而不是gets stdin id:

Expect alters the Tcl gets command so that it doesn't wait for standard input; to read a line while waiting for it, you need to do this instead of gets stdin id:

# Read input to stdin
expect_user -re "(.*)\n"
set id $expect_out(1,string)

这篇关于不用等待期望脚本中的用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆