Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: using open3 to interact with external program--ANSWER FOUND
On Wed, 08 Jun 2005 09:24:43 +0100, darren@birkett.com (D. J. Birkett)
wrote:

>Thomas Bätzler wrote: 

Well I'm a "zen hacker" and like a million monkeys, I sometimes get
lucky.

You may need the latest gpg 1.4.1 for this to work, but I may be wrong.
Anyways, there is a new option for sending commands to gpg, and you
can do what you want with the following script. Try it, it works.

First set the string to "trust\n1\ny\n"  then to "trust\n\5\y\n".
Its funny how 'your' first attempt wasn't so bad after all.

The secret is the --no-tty option  in conjunction with --command-fd
Search the gpg source distribution for details about these commands.

It certainly makes sense now that I see it.

#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;

local $SIG{CHLD} = 'IGNORE';
local $SIG{PIPE} = 'IGNORE';

my $childpid = open3(\*IN, \*OUT, \*ERR,
'gpg  --no-greeting --no-tty  --command-fd 0 --status-fd 1 --edit
zentara');

print IN "trust\n5\ny\n";
close IN;

my(@answer,@err) = ((),());

@answer = <OUT>;
print "out->@answer\n";

@err = <ERR>;
print "err->@err\n";

__END__






--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
Zentara
06-10-05 01:56 AM


Re: using open3 to interact with external program--ANSWER FOUND
zentara wrote:
> On Wed, 08 Jun 2005 09:24:43 +0100, darren@birkett.com (D. J. Birkett)
> wrote:
> 
>
> Well I'm a "zen hacker" and like a million monkeys, I sometimes get
> lucky.
>
> You may need the latest gpg 1.4.1 for this to work, but I may be wrong.
> Anyways, there is a new option for sending commands to gpg, and you
> can do what you want with the following script. Try it, it works.
>
> First set the string to "trust\n1\ny\n"  then to "trust\n\5\y\n".
> Its funny how 'your' first attempt wasn't so bad after all.
>
> The secret is the --no-tty option  in conjunction with --command-fd
> Search the gpg source distribution for details about these commands.
>
> It certainly makes sense now that I see it.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use IPC::Open3;
>
> local $SIG{CHLD} = 'IGNORE';
> local $SIG{PIPE} = 'IGNORE';
>
> my $childpid = open3(\*IN, \*OUT, \*ERR,
>    'gpg  --no-greeting --no-tty  --command-fd 0 --status-fd 1 --edit
> zentara');
>
> print IN "trust\n5\ny\n";
> close IN;
>
> my(@answer,@err) = ((),());

That makes no sense at all, and this being a beginners list I have to point 
it
out.

perldoc perldata
[snip]
You can actually put an array or hash anywhere in the list, but the
first one in the list will soak up all the values, and anything after
it will become undefined.


So the array @answer will receive everything from the assignment.  But the
assignment is superfluous because my() creates empty arrays.


>  @answer = <OUT>;
>  print "out->@answer\n";
>
>  @err = <ERR>;
>  print "err->@err\n";

A "more correct" idiom is:

my @answer = <OUT>;
print "out->@answer\n";

my @err = <ERR>;
print "err->@err\n";

__END__



John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
06-10-05 01:56 AM


Re: using open3 to interact with external program--ANSWER FOUND
On Thu, 09 Jun 2005 14:10:28 -0700, krahnj@telus.net (John W. Krahn)
wrote:
 
>
>That makes no sense at all, and this being a beginners list I have to point
 it
>out.

Yes thanks for pointing it out.  I should have just
my(@answer,@err);


I appreciate your efforts to keep us correct. :-)




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
Zentara
06-10-05 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:47 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.