torriem at gmail.com
Mon Nov 8 13:22:30 MST 2010
On 11/08/2010 11:32 AM, Von Fugal wrote:
> I still love ruby plenty! :) However, I would never recommend it as a
> scripting language. I've tried that numerous times myself when I was
> still in ruby honeymoon. It's more trouble than it's worth. Use
> something scritpy like perl or bash. I'm not sure I'd even recommend
> python for scripting. No, interpreted != scripting language.
I find that Python works pretty well for scripting, but it was missing
an easy way to run a command and then get the return code, the standard
out and standard-err from the process. I can run a command a get stdout
with the os.system() call, which is, IIRC, like the backticks in perl.
But that's not enough sometimes. So I wrote some wrapper code that
makes it easy to spawn a process, feed it input, and get the
above-mentioned output. I've attached it here if anyone wants it. If
you combine this simple module with generators you won't miss piping
processes together; it's not needed 90% of the time. If you do need to
do some piping, you can always run your processes in a sub-shell (one of
the options in my function).
Note that this will give you all the output in one chunk so if you want
to capture a lot of output, use the subprocess module directly and
operate on the pipe. And of course with pipes you can set up generators
which is pretty awesome and almost as fast as bash piping.
Anyway, it's not as quick and dirty as bash by any means, but it's
sufficient to pretty cleanly do what I need in a shell script most of
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the PLUG