Suppress console output in PowerShell

[亡魂溺海] 提交于 2019-11-27 14:17:51

问题


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.


回答1:


Try redirecting the output like this:

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



回答2:


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

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




回答3:


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

Conclusion: Use [void] or > $null.



来源:https://stackoverflow.com/questions/18780956/suppress-console-output-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!