As part of a perl script, I am downloading some files from a website based on cycle numbers obtained from emails. I use a regexp to find the appropriate cycle number, append that to a url and grab an encrypted file from said url. I then print the encrypted file to a temp file, and use gpg to decrypt that temp file, dumping the output into another location. Clear as mud?
Here's where things get interesting. This is the command that is used to decrypt the temp file:
my $cmd = 'cat ~/.gpgkey | gpg --passphrase-fd 0 --no-tty --batch --quiet
--no-mdc-warning --decrypt $filename >> ~/SAT.SCR';
If you'll notice, the command uses a $filename variable. I have separately confirmed that this variable is pointing to the correct file. However, this command yields the following error:
gpg: decrypt_message failed: Unknown system error
If, however, I run the above command straight from the shell (csh), replacing $filename with the actual file, it works perfectly. We are using gpg 2.0.9.
Does anyone have an idea why the decryption is failing when called from the perl script but not from the shell?
Perl doesn't interpolate variables in strings with single quotes. Try using a string with double quotes:
my $cmd = "cat ~/.gpgkey | gpg --passphrase-fd 0 --no-tty --batch --quiet
--no-mdc-warning --decrypt $filename >> ~/SAT.SCR";
system($cmd);
See Quote and Quote-like Operators in perlop for more information.