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

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"?

Replies are listed 'Best First'.
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.


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.

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"; } }
Re: A framework for a shell in perl?
by metaperl (Curate) on May 19, 2010 at 17:40 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://840710]
Approved by Corion
Front-paged by Corion
[robby_dobby]: Likewise! I haven't seen a lot of people with HAs back where I come from, so I figured it might be the same around here too...
[robby_dobby]: Oh, shit -- I was replying to someone, but it wound up here. -_-
robby_dobby is still not used to PM's interface. /o\
[oiskuu]: War. War never changes.
[robby_dobby]: "My cat is a very good mouser" -- that's a great way to identify a Brit among a crowd :-)
thezip looks around to see no one else dancing to Piazzola...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-11-17 19:42 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.