rtaylor1956 has asked for the wisdom of the Perl Monks concerning the following question:

I wrote 2 scripts;

This script WORKS GREAT via command line; %perl -Tw pipetogpg.cgi

# START PIPETOGPG.CGI $ENV{"PATH"} = ""; system('echo "this is a longer test message" | /usr/local/bin/gpg -ear + docwebb > ./Temp/encrypted_file.gpg'); exit; # EOF

This script does NOT WORK (supposed to work via web browser) but it writes an empty file;

#!/usr/bin/perl -Tw use strict; use CGI::Carp qw/fatalsToBrowser/; &encrypt_data; print "Content-type: text/html\n\n"; print "done<BR>"; exit; sub encrypt_data { my $old_path = $ENV{"PATH"}; # CLEAR ENV{"PATH"} SO PERL DOESN'T COMPLAIN ABOUT TAINTED DATA $ENV{"PATH"}=""; # PATH CLEARED ABOVE SO WE NEED A FULL PATH IN THE COMMAND LINE system('echo "this is a longer test message" | /usr/local/bin/gpg - +ear testkey > ./Temp/encrypted_file.asc'); # RESTORE PATH $ENV{"PATH"} = $old_path; } #EOF

I do NOT understand why almost identical code produces an empty file

Thanks

Russ

Replies are listed 'Best First'.
Re: piping data to GnuPG creates empty file
by Anonymous Monk on Jun 28, 2011 at 07:25 UTC

    I do NOT understand why almost identical code produces an empty file

    The code might be almost identical, but the %ENViroment is not, user account and permissions, cwd, chroot, SELinux...

    Also, your program does no error checking, so use GnuPG as it does