Article 4811 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:4811 Path: feenix.metronet.com!news.ecn.bgu.edu!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!sol.ctr.columbia.edu!news.kei.com!ssd.intel.com!chnews!ornews.intel.com!ornews.intel.com!merlyn From: merlyn@ora.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: chat2'open_proc Date: 5 Aug 93 12:38:00 Organization: Stonehenge Consulting Services; Portland, Oregon, USA Lines: 36 Distribution: world Message-ID: References: <23r86fINN22f@srvr1.engin.umich.edu> NNTP-Posting-Host: wyeth.intel.com In-reply-to: garath@brilliant.engin.umich.edu's message of 5 Aug 1993 15:15:27 GMT >>>>> In article <23r86fINN22f@srvr1.engin.umich.edu>, garath@brilliant.engin.umich.edu (Scott Grosch) writes: Scott> I'm trying to open a process to change a users password. I think I need Scott> to use chat2'open_proc() but I'm not sure how. Can someone show me an Scott> example of using that to read from/write to a process. Thanks. ($user,$pass) = "bin","bad boy"; require 'chat2.pl'; &chat'open_proc("passwd $user") || die "Cannot open_proc: $!"; eval { ## presume we don't need old password, cuz we run as root die "bad response: $_ (expected changing...:)" if $_ = &chat'expect(10,'^Changing.*\n',0, '.*\n','$1', TIMEOUT,TIMEOUT,EOF,EOF); die "bad response: $_ (expected ...ssword:)" if $_ = &chat'expect(10,'.*ssword:.*',0,TIMEOUT,TIMEOUT,EOF,EOF); &chat'print("$pass\n"); die "bad response: $_ (expected ...ssword:)" if $_ = &chat'expect(10,'.*ssword:.*',0,TIMEOUT,TIMEOUT,EOF,EOF); &chat'print("$pass\n"); die "bad response: $_ (expected nothing)" if $_ = &chat'expect(10,'\s*\S(.*)','$&',TIMEOUT,TIMEOUT,EOF,0); }; $die = $@; &chat'close(); if ($die) { die $die; } else { print "password changed"; } require 'chat2.pl';&chat'open_proc("echo Just another Perl hacker,");print&chat'expect(10,'.*\n','$&'); -- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095 merlyn@ora.com (semi-permanent) merlyn@kandinsky.intel.com (NEWSREADING ONLY) Quote: "Welcome to Portland, Oregon, home of the California Raisins!"