|There's more than one way to do things|
Automating a shell session: cd does not workby pokki (Monk)
|on Jan 02, 2013 at 15:03 UTC||Need Help??|
pokki has asked for the
wisdom of the Perl Monks concerning the following question:
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):
Lines starting with $ are shell commands, the others are expected output. There are facilities for globs/regexes, comments, etc (not everything demonstrated here). The file above gives me:
... and it all goes downhill from there, because there are other issues with the code. (The full script is there just to show people what I'm working on and hopefully garner criticism as a side-effect; in reality I have a test on pwd right after cd /tmp and it fails as well.) The foo directory doesn't seem to be created anywhere (says find / -iname foo) either, but cd or mkdir don't complain at all (like cat does at the end)
I'm using IPC::Run basically like this (shortened):
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?