在PowerShell中禁止控制台输出 [英] Suppress console output in PowerShell

查看:502
本文介绍了在PowerShell中禁止控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PowerShell脚本中通过以下方式致电GPG:

I have a call to GPG in the following way in a PowerShell script:

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose > $null

我不希望在运行脚本时在主控制台上看到GPG的任何输出.

I don't want any output from GPG to be seen on the main console when I'm running the script.

由于我在PowerShell中的笨拙,所以我不知道该怎么做.我搜索过 Stack Overflow并搜索了一种方法,找到了很多方法,但没有一种有效.

Due to my noobness in PowerShell, I don't know how to do this. I searched Stack Overflow and googled for a way to do it, found a lot of ways to do it, but non of it worked.

例如> $ null"无效.我发现GPG的--quiet --no-verbose选项将较少的输出输出到控制台,但仍然不是完全安静,而且我确信PowerShell中也有一种方法.

The "> $null" for example has no effect. I found the --quiet --no-verbose options for GPG to put less output in the console, still it's not completely quiet, and I'm sure there is a way in PowerShell too.

推荐答案

尝试像这样重定向输出:

Try redirecting the output like this:

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose >$null 2>&1

这篇关于在PowerShell中禁止控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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