简体   繁体   中英

Suppress console output in PowerShell

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.

Try redirecting the output to Out-Null . Like so,

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

尝试重定向输出,如下所示:

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

It is a duplicate of this question , with an answer that contains a time measurement of the different methods.

Conclusion: Use [void] or > $null .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM