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...


In reply to expect module behavior by jimtron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.