Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

expect module behavior

by jimtron (Initiate)
on Mar 11, 2019 at 08:34 UTC ( [id://1231111]=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks,

SO... I have this login for an API. I thought I'd use the expect module, and it seems to work from STDOUT, but the real successful login generates a yaml file that is placed in my home dir.

I think this is just my spacing this interaction, but since the file is deposited as part of another process, and I'm guessing as a sub shell in the module, the file never gets created. Thus I'm not logged in - thus, no love. Or I'm forgetting something entirely.

Is there a way to force the behavior to be executed as part of my user/environs directly? I'm probably overthinking this quite a bit, but figured if anyone might know a simple trick it would be you all. I have tried forcing the ~/file.yml to be created as part of the process, but no love there either, the process won't read it first before asking for an authentication if the server bit isn't set properly - or something, i'm speculating. All this stems from laziness and wanting to use direnv to automate behavior when I enter a directory, really.

Here's the code:

#!/usr/bin/perl use strict; use warnings; use 5.010; use Expect; my $command = "/usr/bin/command"; my @paramaters = qw(login); my $exp = new Expect(); $exp->raw_pty(1); $exp->log_file("./login.log"); $exp->log_stdout(1); $exp->spawn($command, @paramaters) or die "cannot spawn $command: $!\n"; $exp->expect(5, -re =>'API key here:'); sleep 5; $exp->clear_accum(); $exp->send("apikeyhere\r"); $exp->send("\n"); $exp->expect(5, -re => 'Validating key now...'); $exp->expect(5, -re => 'API key OK, logged in now.'); $exp->do_soft_close(); $exp->exitstatus(); print "logged in using expect\n";

any help or kick in the pants would be appreciated...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1231111]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found