David Gerler wrote:
> 
> I have successfully piped a print statement to gpg. My problem is
> coming in when I try to get it back out via a pipe. Can anyone tell
> me, is it possible to send data to a another program and the output
> back with out writing it to a file?
> 
> I want to change the method of piping because of some strange
> problems:
> If I run it from a shell on the server using the -d switch. It
> generates the key and stores it correctly. The problem comes in when I
> run it from the browser. It doesn't generate the key.
> I would also like to change it for security reasons.
> 
> This is my code to pipe it to gpg:

You might want to use one of these:

http://search.cpan.org/search?query=gpg&mode=module


> sub scramble {
> my $number = $_[0];
> my $db = $_[1];
> my $username = $_[2];
> my $exp = $_[3];

While that is correct, this looks better (and is faster.)

my ( $number, $db, $username, $exp ) = @_;


> &makeScratch();

You shouldn't use an ampersand when calling subs.

perldoc perlsub


> if ($OS eq "windows") {
> $outfile = ".\\$scratchPad\\"."temp1.txt";
> $cmd = "c:\\gnupg\\gpg -ea -r ezbid > $outfile";
> } else {
> $outfile = "$scratchPad/"."temp1.txt";
> $cmd = "gpg -ea -r ezbid --always-trust --no-secmem-warning >
> $outfile";
> }

The File::Spec module has methods to handle OS specific paths.

perldoc File::Spec


> open (GPGOUT, "| $cmd") || die "couldn't open GPGOUT";

You should include the $! variable in the error message so you know why
it failed.


> print GPGOUT $number;
> close GPGOUT;

On a piped open you should also check the return value from close.

perldoc -f close
perldoc perlopentut
perldoc perlipc


> open (FILEOUT, "< $outfile") or die "Can't open it: $!";
> while (<FILEOUT>) {
> $temp .= $_;
> }
> close FILEOUT;

Concatenating each line to a variable is inefficient.

perldoc -q "How can I read in an entire file all at once"


> $dbh=$db->prepare("update Members set tempnum = '$temp', ccexpire =
> '$exp'
> WHERE username='$username'");
> $dbh->execute();
> 
> &cleanScratch;
> 
> return 1;
> }
> 
> I have seen something in "Programing Perl"  about socketpairs and
> pipe(read, write) but when I tried it I got very confused.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to