AW: Problem with Perl Call - use "open3"
uwe puchta
u_p@lycos.de
Fri Mar 8 21:57:01 2002
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--=_NextPart_Caramail_0012121015620877_ID
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
the follwoing code works perfect for me - both on Unix and
Win32:
1. package gpgX;
2. use strict;
3. use IPC::Open3;
4. use FileHandle;
5. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
6. sub gpg {
7. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
8. my $f =3D shift || die;
9. -r $f || die 'cannot open file: "' . $f . '"';
10. my $cmd;
11. my $o =3D $f;
12. #$o =3D~ s/\..*?\s*$//i; # removes all extensions
13. $o =3D~ s/\.[^\.]+?$//; # removes only last extension
14. $o .=3D '.gpg';
15. print STDERR "processing file \"$f\" - this might take some
time ... \n";
16. $cmd =3D "gpg.exe -cv --passphrase-fd 0 --s2k-cipher-algo
RIJNDAEL256 -o $o $f";
17. process($cmd);
18. }
19. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
20. sub ungpg {
21. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
22. my $f =3D shift || die;
23. my $o =3D shift || die 'no output file';
24. $f =3D~ /\.gpg\s*$/i or die "$f doesn't have the
extension .pgp";
25. -r $f || die 'cannot open file: "' . $f . '"';
26. print STDERR "processing file \"$f\" - this might take some
time ... \n";
27. print STDERR "output file =3D \"$o\"\n";
28. my $cmd =3D "gpg.exe -v --passphrase-fd 0 -o $o -d $f";
29. process($cmd);
30. }
31. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
32. sub process {
33. #=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0=B0
34. my $cmd =3D shift || die 'missing $cmd';
35. # f=FCr Tests:
36. # $cmd =3D 'perl -e "print <STDIN>;print \"\nstdout -
@ARGV\n\"; print STDERR \"stderr\n\"; "';
37. chomp $gpgX::P; # the passphrase
38. chomp $gpgX::P;
39. warn 'maybe wrong passphrase!'
40. if $gpgX::P =3D~ /^xxx/;
41. my ($writeFH, $readFH, $errFH) =3D (new FileHandle, new
FileHandle, new FileHandle);
42. $readFH->autoflush(); # uncomment this if you
have troubles reading the result
43. # ATTENTION - W A R N I N G: Bechause we use "$cmd"
and not e.g. "@cmd",
44. # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D the command
in $cmd ist processed via THE SHELL.
45. # But: "@cmd" hangs when trying to
read the passphrase
46. # from fd 0. See POD for open2 (not
open3!).
47. my $pid =3D open3($writeFH, $readFH, $readFH, $cmd) ||
die;
48. print $writeFH $gpgX::P;
49. $writeFH->close();
50. while (<$readFH>) { print; }
51. $readFH->close();
52. waitpid $pid, 0;
53. }
54. 1;
in line 16 an 28 use "pgp" (or however your binary is called) -
this is the Win32 Version.
line 37ff: $gpgX::P is where I store my passphrase
Request:
=3D=3D=3D=3D=3D=3D=3D
Please, does anybody have a binary version of PGP 1.0.6 for
SGI IRIX for me?
Regards
Uwe
--------------
mailto:mail@NO-SP-AM-puchta.com -- remove "NO-SP-AM-"
> -------Urspr=FCngliche Nachricht-------
> Guys, I have been trying to feed a passphrase into
> gpg 1.0.6 (on NetBSD, Solaris and Win32) platforms)
> using a variation of a script suggested in some of the
> pgp documentation. Here's what I tried. If somebody
> can tell me why it doesn't work, I'd be Real Pleased ..
> --
> #!/usr/local/bin/perl
> pipe(READER,WRITER);
> if (!fork) {
> close(WRITER);
> $^F=3Dfileno(READER);
> $FilDes=3Dfileno(READER);
> exec "gpg -as --passphrase-fd $FilDes /tmp/outZ" or
> die "can't exec gpg\n";
> }
> close(READER);
> syswrite(WRITER, "secret1\n", 8);
> close(WRITER);
> wait
> --
______________________________________________________
Beginnen Sie das neue Jahr gut informiert: Zeitschriften-Abos zum Sparpreis!
http://www.lycos.de/webguides/entertainment/weihnachten/abo.html
250 Farb-Visitenkarten GRATIS*. In einem Wert von EUR 99,00!
http://www.vistaprint.de/vp/splash/lycosde.asp
Jetzt eigene Domains f=FCr 1,23 Euro/Monat
http://lycos.de.domainnames.com/default.asp?caller=3Dlycos_d_footer
--=_NextPart_Caramail_0012121015620877_ID--