Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Re: Exec Fork Trick

by andreychek (Parson)
on Jul 01, 2001 at 21:05 UTC ( #93035=note: print w/replies, xml ) Need Help??

in reply to Re: Exec Fork Trick
in thread Exec Fork Trick

     The big problem is that /bin/passwd uses your TTY instead of STDIN/STDOUT to interact with the user.
This is absolutally true in most versions of passwd. However, some of the more recent versions of passwd provide you with an option to accept input from STDIN. This is the case with passwd that came with RedHat 7.1, and is packaged as version 0.64. It's described in the man page (man passwd), but in short all you have to say is

passwd --stdin

So ginseng, to modify the code you wrote to make use of this, you could do:
# The runtime options to be passed to passwd my $passwd_options = "--stdin"; # All the arguments to be passed to passwd, including name my @args = qw($passwd_options $name); open (PASSWD, "|-") || exec 'passwd', @args; print PASSWD "$password\n$password\n"; close PASSWD;
Again though, remember that you need a recent version of passwd. Just do a 'man passwd' and check to see if the --stdin option exists. Good luck,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://93035]
[robby_dobby]: Likewise! I haven't seen a lot of people with HAs back where I come from, so I figured it might be the same around here too...
[robby_dobby]: Oh, shit -- I was replying to someone, but it wound up here. -_-
robby_dobby is still not used to PM's interface. /o\
[oiskuu]: War. War never changes.
[robby_dobby]: "My cat is a very good mouser" -- that's a great way to identify a Brit among a crowd :-)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2017-11-17 19:40 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.