TeraMarv has asked for the wisdom of the Perl Monks concerning the following question:

Venerable Monks,

I have the notion to create a shell like environment on Win32 which should include the following features (in no particular order)
* Command History
* Multi-line command input
* Enable editing of multi-line statements retrieved from history
* Encryption/Decryption of password file entries
* Flowthru of DOS commands from shell
* Enable predefined commands to be easily added to shell
* Enable predefined query execution with single command
* Enable ad-hoc query execution
* Enable multiple active ODBC connections and the ability to switch between them
* Enable ODBC auto logon using password lookup from external file

Username and host system to be extracted from command like:-

SYSTEMA:USERNAME:Select * from a_database.some_table limit 10;

* Change prompts to reflect database server which is active at the command line
* Many other things I've not yet though of

If this looks like a stream of consciousness it's because it is. Some of these things may not be viable but I can envisage a tool that would make my life a lot easier.

I have looked at the numerous Term::Readline and Term::Shell modules but am unable to ascertain which one may serve me best, I'd like to avoid reinventing anything that someone else has done far better that I ever could!

Does anyone have experience with any of these shell construction modules that they could share?

Many Thanks,

TeraMarv.

Replies are listed 'Best First'.
Re: Which Module for Win32 Shell
by pc88mxer (Vicar) on Feb 06, 2008 at 16:49 UTC
    I'm taking a stab at what your mean by some of these features, but with the exception of:

    * Enable multiple active ODBC connections and the ability to switch be +tween them

    I think that the Cygwin bash shell might suit your needs. Some of the things bash doesn't do internally can be implemented with auxiliary scripts or shell 'functions'. Specifically, bash can do:

    * Command History * Multi-line command input * Enable editing of multi-line statements retrieved from history * Flowthru of DOS commands from shell * Enable predefined commands to be easily added to shell

    and the rest probably can be implemented as external commands.

    Maintaining active ODBC connections is a potential problem, but I see a couple of different approaches:

    1. Add this feature directly to bash (it's open source).
    2. Create an 'ODBC server process' which would accept commands from some sort of socket connection (either real socket or named pipe), direct them to the appropriate ODBC connection and return the results. The ODBC connections would persist for the lifetime of this server process.

    This would require you to invent a serialization for ODBC commands and results.

    Finally, another thing I'd look into is the Windows PowerShell. One of the things I remember reading about it was that it had extended the stream concept to include streams of objects, not just characters. This would be helpful if you want to pass complex data structures between processes using the pipes paradigm. For instance, how about being able to write something like:

    odbc 'select * from foo' | format-html-table

    The 'lines' emitted by the odbc command are really objects so that it is easy for downstream processes to correctly interpret the row data.

      I suppose I should have specified that this needs to be as vanilla win32 as possible. Once i've finished the tool i'd like to be able to package it as an executable for distribution among my colleagues. Not all of them have Perl, Cygwin or anything else that may make their lives easier....nore are they the types to install these things.

      I was thinking I could use a seperate DBI object for each ODBC connection and select each connection based on the string passed from the user. That makes sense doesn't it?

        If you are interested in a traditional unix type shell, the GnuWin32 project provides windows installers for traditional unix command line tools.

        Another option for unixy-goodness on Win32 is MinGW.

        Zoid, mentioned below, looks like it might be a promising starting point for you, too.


        TGI says moo

Re: Which Module for Win32 Shell
by BrowserUk (Patriarch) on Feb 06, 2008 at 16:33 UTC
      I did look at this but it didn't seem to have a simple interface such as Term::ShellUI for instance. However this may be the right tool for the job? Do you or anyone else have any experience with this module?
Re: Which Module for Win32 Shell
by plobsing (Friar) on Feb 07, 2008 at 06:17 UTC
    Haven't touched it personally, but the zoid shell aspires to do some of what you have asked and provides full access to Perl to do the rest.
Re: Which Module for Win32 Shell
by InfiniteSilence (Curate) on Feb 08, 2008 at 12:52 UTC
    Try
    perl -de 0
    Which will get you into a 'shell like' debugging session. From here you can do these things:

    • * Command History (Press the up arrow -- you may need to run DOSKEY...not sure)
    • * Multi-line command input (use the backslash at the end of commands for multi-line stuff )
    • * Enable editing of multi-line statements retrieved from history (doesn't do this so well, but read on)
    • * Encryption/Decryption of password file entries (write functions to do this and stick them in libraries. Require the libraries)
    • * Flowthru of DOS commands from shell (use backticks or the good old system command);
    • * Enable predefined commands to be easily added to shell (add scripts with functions and require or use do)

    ...

    The previous solutions pretty much cover anything else in your list.

    This environment is a bit clunky, but it can do what you are looking for.

    Celebrate Intellectual Diversity