in reply to Re^3: PGP encryption command not working thru Perl Backticks
in thread PGP encryption command not working thru Perl Backticks

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?

Replies are listed 'Best First'.
Re^5: PGP encryption command not working thru Perl Backticks
by kennethk (Abbot) on Oct 08, 2015 at 16:27 UTC
    There are a few ways to implement this. The classic solution is to fork, set an alarm, and then kill the child thread if it hasn't responded yet; but then you need to get into interprocess communication.

    Probably the most straightforward approach is documented here: Perl 5.8.8 threads, clean exit You would run your backticks in the child thread, and sleep then reap in the parent.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.