Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Wise monks,

I'm in the process of writing a module to test shell sessions using IPC::Run, and I've hit the hurdle described in the subject line: I can't manage to make cd work.

I tried various things until I reread the IPC::Run documentation which states "No support for cd, setenv, or export: do these in an init() sub (example follows)". Okay, but I don't just need cd once to put my script in the right directory, I need a fully interactive session that accepts any command. (Does anyone know why this limitation exists, by the way?)

If you're curious, this is the kind of tool you feed an almost-but-not-quite shell script with the expected output after every command. Then the tool runs every command and compares the output. This is highly useful for teaching material when you need to demonstrate how, e.g., a DVCS works (if you've used Cram before, the example will look rather familiar):

I'm using IPC::Run basically like this (shortened):

my ($input, $output, $errput); my $subprocess = start([ '/bin/bash' ], '<', \$input, '1>pty>', \$output, '2>', \$errput); # later, for each $command { shell => 'pwd', 'outputs' => [ '/tmp/foo' + ] } diag $command->{shell}; $input = $command->{shell} . "\n"; foreach my $expected_output (@{$command->{outputs}}) { while ($output !~ /\n/) { if ($errput) { diag 'STDERR: '.$errput; $errput = ''; } $subprocess->pump; } # munge $expected_output and compare stuff }

Does anyone automate shell(or other CLI apps) sessions to this degree? With what module? Looking around on CPAN it seems only IPC::Run really does the whole "talk to a subprocess double-pipe style" hog. I don't get why bash seems to "reset" between every command, though. Did I miss something really obvious?

In reply to Automating a shell session: cd does not work by pokki

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2018-01-21 23:39 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (230 votes). Check out past polls.