Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for looking!#!/usr/bin/perl use strict; use warnings; use File::Slurp; use Data::Dumper; $| = 1; # Encrypt file. my $gpg_command = `gpg --trust-model always -er 12345678 my_file.txt`; print defined($gpg_command) ? $gpg_command : "Command failed\n"; # Capture STDOUT and save it to a file. open(READ, "$gpg_command 2>&1 |") or die "Failure on open $!\n"; open( my $out, ">", "encrypted.pgp" ) or die "Could not open file for + encrypted data - $!"; while (<READ>) { my $output .= $_; print $out $output; } close $out or die "1 Failure on close $!\n";; close (READ) or die "2 Failure on close $!\n"; print "\nDone.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capture response from backticks to a file.
by kcott (Archbishop) on Nov 13, 2013 at 20:04 UTC | |
|
Re: Capture response from backticks to a file.
by dsb (Chaplain) on Nov 13, 2013 at 19:26 UTC | |
by Anonymous Monk on Nov 13, 2013 at 19:40 UTC | |
by astroboy (Chaplain) on Nov 13, 2013 at 19:53 UTC | |
by Anonymous Monk on Nov 13, 2013 at 20:03 UTC | |
by Anonymous Monk on Nov 13, 2013 at 20:28 UTC | |
|
Re: Capture response from backticks to a file.
by marinersk (Priest) on Nov 13, 2013 at 21:17 UTC |