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

Hello perlmonks,
I am trying to use perlipc open2 module for writing a wrapper over passwd command. Below is the code which I took from this site.

At Line X in below code, I need to read what passwd command is asking, Current password or new password and depending on that I need to supply old or new password.
.

Can anyone please tell me how to do that.Any help would be greatly appreciated

Thanks,
Sajid

my $pid = open2( \*Reader, \*Writer, "passwd" ) or warn $!;
Writer->autoflush();
Reader->autoflush();
STDIN->autoflush();
$SIG{ALRM} = sub {die}; # required for alarm call below
do {
print ": "; # simple prompt
#my $cmd = <STDIN>;
#print Writer $cmd;
my $got;
while (1) {
eval { alarm 3; $_=<Reader> }; # get line in 3 seconds or stop reading
$got .= $_; // Line X
print Writer "mypassword1";
alarm 0;
last if ($@ or !(defined($_))); # exit loop if there was a timeout or no data
#$got .= $_;
#print $got
}
# print $got;
} while(1);

Replies are listed 'Best First'.
Re: Perlipc open2 question
by betterworld (Curate) on May 22, 2007 at 11:52 UTC
    AFAIK, most passwd programs are not controllable via pipes. Maybe Expect works better for this problem, as it emulates a terminal.
      I am looking for pipes,I plan to use this from mod perl from Apache.
        Any replies for this, Any idea would be useful