gpt4 book ai didi

linux - 从 Expect Script 执行对话框命令

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:35:51 26 4
gpt4 key购买 nike

我在 TCLSH 中测试了下面的行并且它有效:

dialog --title "Text" --msgbox "Text" 8 60

但是,如果我在带有“exec”的 Expect 脚本中尝试它,它只会挂起:

exec dialog --title "Text" --msgbox "Text" 8 60

我做了一点研究,似乎不需要转义特殊字符,但也许这就是问题所在?

你们有什么建议可以让这段代码正常工作吗?谢谢!

最佳答案

默认情况下,交互式 tclsh 会表现得像一个 shell(如 Bash),它会将未知命令作为外部可执行文件和自动处理执行它们。这就是为什么您可以直接从 tclsh 中运行 dialog 的原因。这可以通过定义 global auto_noexec 变量来关闭。例如:

[bash] # tclsh
% echo hello world
hello world
% set auto_noexec "the value does not matter"
1
% echo hello world
invalid command name "echo"
%

对于 exec 命令,默认情况下它不会将输出打印到终端。您应该使用 >@stdout 或/和 2>@stderr:

exec dialog --title Text --msgbox Text 8 60 >@ stdout 2>@ stderr

关于linux - 从 Expect Script 执行对话框命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32241162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com