exec 不在期望脚本中工作
我正在编写我的第一个expect脚本,所以我可能会遗漏一些明显的东西,但我发现以下内容相当令人费解:
$ expect
expect1.1> exec echo a
a
expect1.2>
$ cat > test.exp
exec echo a
$ expect test.exp
$
如果我运行expect并使其手动执行某些内容,它就会起作用。如果我将相同的命令放入脚本中,它将不起作用。这是怎么回事?
I'm writing my first expect script, so I may be missing something obvious, but I find the following quite puzzling:
$ expect
expect1.1> exec echo a
a
expect1.2>
$ cat > test.exp
exec echo a
$ expect test.exp
$
If I run expect and make it exec something manually, it works. If I put the same command in a script, it doesn't work. What's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,expect 本质上是 Tcl 的扩展。 Tcl 的
exec
执行外部命令,捕获输出并将其作为值返回 - 它不会将其发送到 stdout,除非您指示它到。然而,为了方便起见,交互式 Tcl(或期望)会话会将输出打印到 stdout。您的脚本应该是:
我假设“echo a”是更复杂的外部命令的占位符。如果您只想打印一些内容:
如果您是 Tcl 新手并且期望那么您应该 先学Tcl。
Note that expect is essentially an extension of Tcl. Tcl's
exec
executes the external command, captures the output and returns it as a value -- it does not send it to stdout unless you instruct it to. However, an interactive Tcl (or expect) session prints the output to stdout as a convenience.Your script should be:
I'm assuming "echo a" is a placeholder for a more complicated external command. If you just want to print something:
If you're new to Tcl as well as expect then you should learn Tcl first.