[Pythonmac-SIG] interaction with OS X commands

Bob Ippolito bob at redivi.com
Tue Oct 19 00:02:48 CEST 2004

On Oct 18, 2004, at 17:36, brad.allen at omsdal.com wrote:

> This is a bit of a sidetrack from the original topic involving the OS X
> dock, so I changed the subject header for this thread. My reply to Bob 
> is
> posted below:
> Bob Ippolito <bob at redivi.com> wrote on 10/17/2004 12:22:07 PM:
>> On Oct 17, 2004, at 9:57 AM, brad.allen at omsdal.com wrote:
>>> Bob Ippolito <bob at redivi.com> wrote on 10/15/2004 12:26:54 PM:
>>>> - The way you call the defaults application is HORRENDOUS!  Wow.  I
>>>> highly suggest using the subprocess module (formerly process, 
>>>> formerly
>>>> popen5) that is going to be in Python 2.4, or at least
>>>> os.spawnl/os.spawnv:
>>> I've used this "getCommandOutput" function fairly extensively with
>>> success,
>>> so I'd like to find out what's wrong with it.
>>> #at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52296
>> It uses a string for the command line, instead of an array, which 
>> makes
>> for really ugly and fragile code.  Subprocess wouldn't be going into
>> Python 2.4 if it wasn't a vast improvement over the existing
>> facilities.
> Ok; that's a useful criticism. Using os.spawnv looks like a good way to
> execute some commands in which I need to don't need capture output, 
> such as
> the defaults command. In those cases just need to know the exit status 
> (1
> or 0), which os.spawnv does provide. However, the os.popen approach 
> appears
> more useful when I want to capture the output of a command. 
> Unfortunately,
> the popen variants only accept a string argument.

That is why I presented os.spawnv as a "worst case" alternative to the 
subprocess module!  Please stop using popen, getCommandOutput, etc.  
They all suck, use subprocess.


More information about the Pythonmac-SIG mailing list