http://www.perlmonks.org?node_id=515532

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

Fellow Monks!

I'm working on this for over 2 days now to no avail, and I must admit IPC is one of my weakest fields. I have got the task to automate resetting passwords without user input on AIX /w HACMP. Although I'm allowed to test as root user, I'm not allowed to install any modules like Expect.

When I run the external command over the command line, I type in the passwords which get not displayed and all is OK:

# /usr/es/sbin/cluster/sbin/cl_chpasswd -cspoc -f -k testuser Changing password for "testuser" testuser's New password: Enter the new password again: # echo $? 0 #

When run by my test script and hitting <Ctrl+C> after the second password display:

# ./test.pl testuser's New password: testpass testpass 3004-657 Terminating from signal. # echo $? 130 #

When run by my test script and typing in the password followed by <ENTER> after second password display:

# ./test.pl testuser's New password: testpass testpass Enter the new password again: # echo $? 0 #

So I can see the passwords get printed but the external program doesn't get the input.
Any ideas?
Thanks in advance!
Below my test script:

#!/usr/bin/perl use strict; use warnings; $ENV{ODMDIR} = '/etc/objrepos/'; # needed for external program my $user = 'testuser'; my $password = 'testpass'; my $cmd = "/usr/es/sbin/cluster/sbin/cl_chpasswd -cspoc -f -k $user"; #print $cmd, $/x2; # verified - OK use IPC::Open2; my $pid = open2(*Reader, *Writer, $cmd); # No success with following variations: #my $pid = open2(*Reader, *Writer, "$cmd </dev/tty"); #my $pid = open2(*Reader, *Writer, "$cmd </dev/tty >/dev/tty"); $| = 1; # Verify device: #use POSIX; #my $tty = POSIX::ctermid(); #print "\nTTY: '$tty'\n\n"; # prints: TTY: '/dev/tty' local *STDOUT; open( STDOUT, ">>/dev/tty" ); # wait until external program is ready sleep 5; # Enter password: #print Writer "$password\n"; # neither displayed nor accepted as input print "$password\n"; # will be displayed but not accepted as input sleep 2; # Repeat password: #print Writer "$password\n"; print "$password\n"; waitpid $pid, 0; close Reader; close Writer;