[Newbies] PipeableOSProcess shell interaction

David T. Lewis lewis at mail.msen.com
Mon Jun 17 23:38:10 UTC 2013


On Mon, Jun 17, 2013 at 10:16:05AM -1000, OpenSlate ChalkDust wrote:
> On Wed, Jun 12, 2013 at 2:47 AM, David T. Lewis <lewis at mail.msen.com> wrote:
> 
> > On Tue, Jun 11, 2013 at 10:34:47PM -0700, Sean P. DeNigris wrote:
> > > When using PipeableOSProcess as a shell, how can I get feedback on the
> > status
> > > of the individual commands?
> > [snip]
> > PipeableOSProcess is designed to be part of CommandShell, so when you use
> > it
> > directly (rather than using a CommandShell), you need to take care of a few
> > details. The important things are to set the output pipe for nonblocking
> > reads
> > (otherwise you will hang up your VM on a read), and to close pipes when you
> > are done using them (otherwise you will "leak" file handles over time).
> >
> > Dave
> >
> >
> Could the example you gave be implemented using CommandShell? In what
> situations would I want to use PipeableOSProcess instead of CommandShell?

Good question. CommandShell works at a higher level, and it manages the
annoying details of closing pipe handles and making sure that you do
not block the VM. In most cases, it is easier to use CommandShell rather
than operating directly on the lower level PipeableOSProcess.

For example (to build on the earlier example), if you want to run the
Unix 'ls' command, and check its exit status to determine if a file was
not found, it is not necessary to use the lower level PipeableOSProcess.
You can do this instead:

  CommandShell new
    if: 'cd .. ; ls aFile'
    then: ['the ls command succeeded']
    else: ['the file was not found'] ==> 'the file was not found'

Having said that, CommandShell is a simple simulation of a Unix shell,
and it is not a complete replacement for something like bash. There
are cases when you may need to use the features of a real Unix shell,
so working directly with a PipeableOSProcess connected to /usr/bin/bash
may be necessary in some cases.

Dave



More information about the Beginners mailing list