Linux 隐藏预期的输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14601526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:51:17  来源:igfitidea点击:

Hide output from expect

linuxexpect

提问by yegong

Here's part of an expect script

这是预期脚本的一部分

#/usr/bin/expect 

spawn -noecho kwalletcli -f Passwords -e keyofmypassword
expect ".*"
set passwd $expect_out(buffer)

# do some thing
# ...

It read password from kwalletcli, and store in variable passwd. So I can connect to the servers with this passwd.

它从 kwalletcli 读取密码,并存储在变量中passwd。所以我可以用这个连​​接到服务器passwd

However, the output of kwalletcli is pass through expect and show on console. How can I hide that.

但是,kwalletcli 的输出是通过 expect 并在控制台上显示的。我怎么能隐藏呢。

采纳答案by glenn Hymanman

Try adding

尝试添加

log_user 0

to your script. That should turn off the display to stdout.

到你的脚本。那应该关闭显示到标准输出。

If you want to turn it on again for the "do some thing" part of the program, re-enable it

如果您想为程序的“做某事”部分再次打开它,请重新启用它

log_user 1

回答by Hamid Reza Moradi

using this command:

使用这个命令:

exec >log 2>&1

you can forward your output to a file or you can pass it to dev/null

您可以将输出转发到文件,也可以将其传递给 dev/null