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.
You can either run it like this (but this shows a window for a while): PowerShell.exe -WindowStyle hidden { your script.. } Or you use a helper file I created to avoid the window called PsRun.exe that does exactly that. You can download the source and exe file from Run scheduled tasks with WinForm GUI in PowerShell.
The Out-Null cmdlet sends its output to NULL, in effect, removing it from the pipeline and preventing the output to be displayed at the screen.
The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.
Try redirecting the output to Out-Null. Like so,
$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose | out-null
Try redirecting the output like this:
$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose >$null 2>&1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With