Search code examples
linuxperlshellcommandexecute

Run Shell command in Perl


I can run some Shell Linux commands in Perl (for example create a folder). But I can't execute followed command:

echo 'mypassword' | gpg --passphrase-fd 0 --output outfile --decrypt inputfile

I add this command in .sh file and could execute in Shell fine. but when I call .sh file, Perl couldn't run it. I used open3, system, open commands to run. I could run other .sh file, but not for this command.

Can you help me please?


Solution

  • Try using backquote/backtick, seems to work fine:

    #!/usr/bin/perl
    use strict;
    
    `echo 'mypassword' | gpg --passphrase-fd 0 --output outfile --decrypt inputfile`
    

    P.S. I would better use some cpan module like GPG.