Opened 8 years ago

Closed 4 years ago

Last modified 4 years ago

#5390 enhancement closed wontfix (wontfix)

Process support on Win32 cannot make use of PATH

Reported by: philmayers Owned by: Greg MacDonald
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

Twisted does not offer any way to execute a process searching PATH on windows. This is important if you want, for example, to do:

 d = utils.getProcessOutput('powershell.exe', args, ...)

...because you probably don't want to hard-code the path to interpreters and so forth.

This seems to happen because the code in t.i._dumbwin32proc basically does this:

 # command, args supplied from outside
 args = quoteArgs(args)
 process = win32process.CreateProcess(command, args, ...)

Now, win32process.CreateProcess is a straight mapping to the Win32 CreateProcess API, which supports two modes:

  1. 1st argument contains absolute path of exe, 2nd arg contains string of arguments not including exe
  2. 1st argument is null, 2nd argument contains exe then arguments; if there is no pathsep in the exe, PATH is searched

You can't force Twisted to do this, because it won't accept "None" as the executable in any of the Process APIs.

It would be relatively simple to change dumbwin32proc to do:

 if not '\\' in command:
   args.insert(0, command)
   command = None
 args = quoteArgs(args)
 process = win32process.CreateProcess(command, args, ...) 

Attachments (1)

twisted-w32-create-process.patch (1.2 KB) - added by Greg MacDonald 4 years ago.

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by Greg MacDonald

comment:1 Changed 4 years ago by Greg MacDonald

I've created a patch that fixes this issue. Still need to write a unit test. Such a small change though. Is it really warranted?

comment:2 Changed 4 years ago by Greg MacDonald

Keywords: review added

comment:3 Changed 4 years ago by Jean-Paul Calderone

Keywords: windows win32 process review removed
Owner: set to Greg MacDonald

Hi. Thanks for your contribution. Yes, even a change as small as this one requires a unit test which demonstrates that it works. Thanks.

comment:4 Changed 4 years ago by Glyph

In addition to being untested, this is also an incompatible change in behavior, since it will search the path now where it wouldn't before. Not searching the path is a security feature: spawnProcess is a primitive which only executes exactly the executable you've passed.

It would be good to add some higher-level functionality, or perhaps a flag, that caused path-searching to happen, but just doing it unconditionally by default would not be a good way to go.

comment:5 Changed 4 years ago by Greg MacDonald

Resolution: wontfix
Status: newclosed

Ok, sounds like it might be best to leave it as it is. And people can use their os-specific path searching functions before calling spawnProcess. Thanks!

comment:6 in reply to:  5 Changed 4 years ago by Glyph

Replying to gtmacdonald:

Ok, sounds like it might be best to leave it as it is. And people can use their os-specific path searching functions before calling spawnProcess. Thanks!

I think that we may have another ticket buried here - should twisted.python.procutils.which have logic for honoring %PATHEXT% when run on Windows?

Note: See TracTickets for help on using tickets.