Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Automating a shell session: cd does not work

by Illuminatus (Curate)
on Jan 02, 2013 at 22:31 UTC ( #1011365=note: print w/ replies, xml ) Need Help??


in reply to Automating a shell session: cd does not work

Did I miss something really obvious?
Well...

The following code shows a successful 'cd' for me

#! /usr/bin/perl use strict; use IPC::Run qw( start pump finish ); my ($input, $output, $errput); $input=""; $output=""; my $subp = start([ '/bin/bash' ], \$input, \$output, \$errput) or die $@; print $errput; $input .= "cd /work/drjohnson\n"; pump $subp until length $input == 0; $input .= "pwd\n"; pump $subp until $output =~ /\n/; print "$output\n"; $subp->finish;
If you have a runnable example of where it doesn't work for you, I'd be glad to try it. You might also try IPCRUNDEBUG. Do an 'export IPCRUNDEBUG=details' before running your script. I believe what the author meant was that you couldn't do things like 'cd' (well, chdir) in your parent script between pump calls.

fnord


Comment on Re: Automating a shell session: cd does not work
Download Code
Replies are listed 'Best First'.
Re^2: Automating a shell session: cd does not work
by pokki (Scribe) on Jan 02, 2013 at 23:52 UTC

    Yes, your example works for me too. I'll take a closer look at my code, there's probably a glaring mistake somewhere in my loop. I'll sleep over it and see if my brain can spot it better tomorrow :)

    In any case this will probably end on Bitbucket soonish for the world to poke at it and point more bugs, so if I haven't found anything tomorrow I'll take you up on your offer and post the repo URL here.

    Thanks for your time and hints so far.

Re^2: Automating a shell session: cd does not work
by pokki (Scribe) on Jan 03, 2013 at 10:13 UTC

    OK, it was definitely my fault. I keep telling myself I need to stop assuming the modules I use are at fault.

    I was doing $input = "new command\n" instead of $input .= "new command\n", so I guess in some cases existing input got clobbered before being pumped into the harness.

    Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2015-07-30 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls