diff options
author | Greg Ward <gward@python.net> | 1999-08-29 18:20:56 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 1999-08-29 18:20:56 (GMT) |
commit | 69628b0ad10f89a65902f5b911d1040ed9ae1ca2 (patch) | |
tree | 671172eafbf43ee6ef5855c5f9ce8ef246d35847 /Lib/distutils/spawn.py | |
parent | 1ea8af2fe03a97abb9bce897b2fe9c6dae6940b7 (diff) | |
download | cpython-69628b0ad10f89a65902f5b911d1040ed9ae1ca2.zip cpython-69628b0ad10f89a65902f5b911d1040ed9ae1ca2.tar.gz cpython-69628b0ad10f89a65902f5b911d1040ed9ae1ca2.tar.bz2 |
Patch from Perry Stoll: support for Windows.
Diffstat (limited to 'Lib/distutils/spawn.py')
-rw-r--r-- | Lib/distutils/spawn.py | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py index 24e76ef..3a0702d 100644 --- a/Lib/distutils/spawn.py +++ b/Lib/distutils/spawn.py @@ -33,23 +33,42 @@ def spawn (cmd, if os.name == 'posix': _spawn_posix (cmd, search_path, verbose, dry_run) - elif os.name == 'windows': # ??? - # XXX should 'args' be cmd[1:] or cmd? - # XXX how do we detect failure? - # XXX how to do this in pre-1.5.2? - # XXX is P_WAIT the correct mode? - # XXX how to make Windows search the path? - if verbose: - print string.join (cmd, ' ') - if not dry_run: - os.spawnv (os.P_WAIT, cmd[0], cmd[1:]) + elif os.name in ( 'nt', 'windows' ): # ??? + _spawn_nt (cmd, search_path, verbose, dry_run) else: raise DistutilsPlatformError, \ "don't know how to spawn programs on platform '%s'" % os.name # spawn () +def _spawn_nt ( cmd, + search_path=1, + verbose=0, + dry_run=0): + import string + executable = cmd[0] + if search_path: + paths = string.split( os.environ['PATH'], os.pathsep) + base,ext = os.path.splitext(executable) + if (ext != '.exe'): + executable = executable + '.exe' + if not os.path.isfile(executable): + paths.reverse() # go over the paths and keep the last one + for p in paths: + f = os.path.join( p, executable ) + if os.path.isfile ( f ): + # the file exists, we have a shot at spawn working + executable = f + if verbose: + print string.join ( [executable] + cmd[1:], ' ') + if not dry_run: + # spawn for NT requires a full path to the .exe + rc = os.spawnv (os.P_WAIT, executable, cmd) + if rc != 0: + raise DistutilsExecError("command failed: %d" % rc) + + def _spawn_posix (cmd, search_path=1, verbose=0, |