68

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

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

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

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.

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.

4

3 回答 3

118

尝试将输出重定向到Out-Null。像这样,

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

于 2013-09-13T09:12:50.947 回答
47

尝试像这样重定向输出:

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose >$null 2>&1
于 2013-09-13T09:20:11.623 回答
6

它是这个问题的副本,其答案包含不同方法的时间测量。

结论:使用[void]or > $null

于 2016-12-06T11:05:26.243 回答