Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

A framework for a shell in perl?

by Anonymous Monk
on May 19, 2010 at 14:11 UTC ( #840710=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm developing a linux based hardware device and plan to provide a Cisco IOS-like command line interface. I've considered rolling my own, but would rather not re-invent the wheel. Can anyone recommend a good Perl based framework for developing such a "shell"?

Comment on A framework for a shell in perl?
Re: A framework for a shell in perl?
by jettero (Monsignor) on May 19, 2010 at 14:18 UTC
    Wheel::ReadLine is tip top. You have command events and everything just works. POE can be a little frightening at first, but you'll get the hang of it.

    -Paul

Re: A framework for a shell in perl?
by elwarren (Curate) on May 19, 2010 at 15:43 UTC
Re: A framework for a shell in perl?
by skx (Parson) on May 19, 2010 at 16:43 UTC

    The last time I needed such a think I used readline and did it manually because reading and parsing isn't difficult.

    However that was before I knew about Term::Shell, which looks like it would suit your needs.

    Steve
    --
Re: A framework for a shell in perl?
by metaperl (Curate) on May 19, 2010 at 17:40 UTC
Re: A framework for a shell in perl?
by Khen1950fx (Canon) on May 20, 2010 at 10:01 UTC
    Here's an example to get you started. There are three commands: system, version, and exit. Note that subs for the commands start with "sub run_system", etc. Prefix run to the command. I don't have any Cisco devices, so I can't help you there.
    #!/usr/bin/perl use strict; use warnings; my $obj = cios->new(); $obj->cmdloop; package cios; use base qw(Term::Shell); use CPAN; sub prompt_str { my $cwd = 'cwd'; $cwd =~ s[^\Q$ENV{HOME}\E][~]; "cios> " } sub run_system { print "\nYour System:\n", "Perl $]\n", "$^O\n", "$0\n\n"; } sub run_version { my $mod = 'Term::Shell'; for $mod(CPAN::Shell->expand("Module", $mod)) { print "The current version is: ", $mod->cpan_version, "\n", "The installed version is: ", $mod->inst_version, "\n", $mod->inst_file, "\n"; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (17)
As of 2014-11-24 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (144 votes), past polls