Is python a good choice for this task?

Harry George hgg9140 at seanet.com
Wed Nov 13 16:47:27 EST 2002


Justin Sheehy <justin at iago.org> writes:

> claird at lairds.com (Cameron Laird) writes:
> 
> >>why not recommend the "commands" module instead of popen for those uses?
> 
> > I claim to observe that Python adepts more rarely recommend commands
> > than popen2.  I'll speculate that this is an artifact of commands'
> > late appearance in Python's standard distribution (was it 1.5?).
> 
> Agreed.  I sometimes forget about its existence.
> 
> > *I*'ve never been able to get commands to do anything useful under Windows.
> 
> True enough.  However, in most cases where I've seen someone asking
> how to get the output of some command inside a Python script, their
> program was by its nature not going to be portable.  Thus, if commands
> works on their platform, it may be the best choice for the job.
> 
> Mind, I do not claim that Python programs in general that use external
> processes are not or can not be portable.  The difference is that the
> people that were already writing portable code for this purpose didn't
> have to ask how to spawn a subprocess.  <wink>
> 

I recently helped someone with the classic "run a script from inside
python and get the output".  I recommended using commands.getoutput.
it worked on Linux but not AIX.  Then we went to popen2, and that
worked fine on both platforms.  A few more such experiences, and I
guess I'll be suggesting pipes first, too.

Of course, the real answer is for the complainer (e.g., me) to go look
at the "getoutput" code and figure out why it was having problems,
propose and test the solution, and help the whole community.  Just too
busy right now.

> > at some point I need to figure out what my problems with commands on
> > NT and W95 are
> 
> Sadly, I doubt that these problems are local to you.  From the docs:
> 
> "Availability: Unix."
> 
> It will generally import successfully on windows, but can not be
> counted on to work there.  This is the real answer to my question.
> 
> The question was somewhat rhetorical.  I simply think that the
> commands module occasionally deserves mention, even if it is not yet
> as wonderfully portable as the rest of Python.
> 
> All of this said, I can't argue against the ease of use of [exec] and
> similar facilities in Tcl.  I don't enjoy Tcl much myself, but that is
> certainly one of its strengths.
> 
> -Justin
> 
>  
> 
> 
> 
> 
> 

-- 
Harry George
hgg9140 at seanet.com



More information about the Python-list mailing list