Search code examples
windowspowershellencryptionerror-handlinggnupg

Native Command Error GPG Powershell


We are using GPG to encrypt/decrypt files. This gpg is being called in a powershell as follows

 gpg -o $myOfile -d $myDfile
                      #Check if decryption succeeded
                        If($?)
                        {
                          Echo "`nDecryption of $myDfile succeeded"
                          Echo "Decrypted file is $myOfile`n"

When we run the script, the decryption is taking place correctly. After the decryption is done, the script fails with the below error

  • CategoryInfo : NotSpecified: (gpg: Signature ...key ID XXXXXXX:String) [], RemoteException
    • FullyQualifiedErrorId : NativeCommandError

I looked up answers for a few other questions with similar answer but none of the suggestions are working. Any help would be greatly appreciated

Thanks, Sree


Solution

  • $? is not used for the console apps, but for Powershell cmdlets. Try with

    if (!$LastExitCode) {
    
    }