[Twisted-Python] Windows <strike>i hate it</strike> Process API

Christopher Armstrong radix at twistedmatrix.com
Mon Apr 7 22:49:19 EDT 2003

So, I've discovered[1] something new about Windows. Basically, there's
no such thing as `argv' in win32-land, and each program has to parse
its command-line manually (I had known that they had to do wild-card
expansion manually, but not parse the entire damned string). This
isn't so much the problem as there is no sane Win32 API for starting a
process with a sequence of arguments. The reason this is a problem is
that Twisted's Process API uses sequences of arguments.

In light of this, I have a few somewhat-orthogonal proposals to make,
but I think they should all be done (well, except, perhaps, the last):

 * Add a method to the Win32 Process Interface (IWin32Process?) that
   accepts a string rather than an executable and a list of args. We
   should allow people to use the (unfortunately) sanest method
   available for starting processes on Windows.

 * Add a warning to win32eventreactor.Process.__init__ (in the case
   that the user passed in a sequence of args) that tells people about
   this problem.

 * Add some auto-quoting evilness[2] to
   win32eventreactor.Process.__init__, for when arguments are passed
   as a sequence. What we have there absolutely sucks (" ".join), and we
   should probably at least try to make the existing API as reliable 
   as possible.

 * Perhaps make the string "command-line" API available on
   PosixProcess as well, so people can use either the string or the
   sequence API and expect at least some bit of cross-platformness (but
   I'm fine with telling people to just use the sequence API if others
   don't like this, especially considering this either requires
   calling out to a shell (gah), or doing some unfun argument-splitting.)

*whimper* :-(

[1] http://mail.python.org/pipermail/python-win32/2003-April/000906.html
[2] <exarkun> ' '.join(['"%s"' % (s.replace('\\', '\\\\').replace('"',
              '\\"')) for s in args[1:]])

 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+     http://twistedmatrix.com/users/radix.twistd/

More information about the Twisted-Python mailing list