Python as a scripting language. Alternative to bash script?

Michael Torrie torriem at gmail.com
Mon Jun 28 14:25:51 EDT 2010


On 06/28/2010 12:05 PM, Dave Pawson wrote:
> On 28 June 2010 18:39, Michael Torrie <torriem at gmail.com> wrote:
> 
>> Sure.  I've created a module called runcmd that does 90% of what I 
>> want (easy access to stdout, stderr, error code).  I've attached
>> it to this e-mail.  Feel free to use it; this post puts my code
>> into the public domain.
> 
> Request please Michael.
> 
> Examples of usage in the docstring?

Well the simplest form is as I showed in my e-mail:

(err,stdout,stderr) = runcmd.run (['command','arg1','arg2', ... ])

An example where you need to pass stdin:

input="some string\n"
(err,stdout,stderr) = runcmd.run (['cmd','arg1',], stdin=input)

err is the return error code (int) and stdout and stderr are the strings
the result from the process's output, both strings.

There are some other features (or bugs probably) that you can get from
the source code itself.  I think at one time I wanted to be able to have
callbacks that would do something with stdout and stderr (in a
real-time, unbuffered way), but I have never used them and don't think
they work.



More information about the Python-list mailing list