Backticks return the output of the code, not the exit status. If you want that, you probably want system, where
The return value is the exit status of the program as returned by the wait call. To get the actual exit value, shift right by eight (see below). See also exec. This is not what you want to use to capture the output from a command; for that you should use merely backticks or qx//, as described in `STRING` in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).
$dataFile = '/opt/ExportedPGPKeys/SampleData.txt';
$isEncrypted = system(qw'pgp -ea +batchmode', $dataFile, @sys);
print " The output value is $isEncrypted \n";
You should note the most current Perl is 5.22, and I think 5.14 is already EOL'd. Not that old versions don't work just fine, and not that old versions aren't still bundled in modern OS's.
Your lack of my makes me concerned that you are learning old-style Perl. See for example Use strict warnings and diagnostics or die or Modern Perl.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [d/l] |
Thanks kennethk. I have modified my code to below
my $dataFile = '/opt/ExportedPGPKeys/SampleData.txt';
my $isEncrypted = `pgp -ea +batchmode $dataFile 0xc33721`;
#0xc33721 is the public key ID.
print " The output value is $isEncrypted \n";
I wanted just the output of the command so sticking to Backticks, but I wanted to address a scenario where during the execution of the PGP command for some reason if the cursor dont return to the perl code and stuck during the command execution itself say for 10 seconds, then I want to terminate(die) or force exit this perl run and log an error.
Is there a possibility to achieve this?
| [reply] [d/l] |
| [reply] |