Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Responding to terminal I/O

by CountOrlok (Friar)
on Apr 17, 2013 at 19:00 UTC ( #1029199=note: print w/replies, xml ) Need Help??


in reply to Re^2: Responding to terminal I/O
in thread Responding to terminal I/O

this should get you started:
use strict; use warnings; use Expect; my $timeout = 5; my $password = "password"; my $shell_prompt = ']$ '; my $exp = new Expect; $exp->raw_pty(1); $exp= Expect->spawn("su") or die "Error calling su: $!\n"; unless ($exp->expect(5,"Password: ")) { die; # add error handling }; $exp->send("$password\n"); unless ($exp->expect(5, $shell_prompt)) { die; # add error handling }; print "Login successful\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029199]
help
Chatterbox?
[tye]: because s/// doesn't support an 'r' option?
[tye]: (in your version of Perl?)
[tye]: no, thankfully (at least my version of Perl) has a different error for that.
[tye]: could be an unclosed m//, qr//, s///, or even q// (etc.) from earlier

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2016-12-07 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (131 votes). Check out past polls.