Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/spawn.py @ 25135:0f0016632be4 legacy-trunk
_formatparam(), set_param(): RFC 2231 encoding support by Oleg
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Fri, 06 Sep 2002 03:55:04 +0000 |
| parents | ca87119255eb |
| children | f465d6692bde |
| rev | line source |
|---|---|
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.spawn |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
3 Provides the 'spawn()' function, a front-end to various platform- |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
4 specific functions for launching another program in a sub-process. |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
5 Also provides the 'find_executable()' to search the path for a given |
| 14861 | 6 executable name. |
| 7 """ | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
9 # created 1999/07/24, Greg Ward |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 |
|
11897
017e592c0fd2
Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents:
11665
diff
changeset
|
11 __revision__ = "$Id$" |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
13 import sys, os, string |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
14 from distutils.errors import * |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
15 from distutils import log |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
16 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
17 def spawn (cmd, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
18 search_path=1, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
19 verbose=0, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
20 dry_run=0): |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
21 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
22 """Run another program, specified as a command list 'cmd', in a new |
| 14861 | 23 process. 'cmd' is just the argument list for the new process, ie. |
| 24 cmd[0] is the program to run and cmd[1:] are the rest of its arguments. | |
| 25 There is no way to run a program with a name different from that of its | |
| 26 executable. | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 |
| 14861 | 28 If 'search_path' is true (the default), the system's executable search |
| 29 path will be used to find the program; otherwise, cmd[0] must be the | |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
30 exact path to the executable.If 'dry_run' is true, |
| 14861 | 31 the command will not actually be run. |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
32 |
| 14861 | 33 Raise DistutilsExecError if running the program fails in any way; just |
| 34 return on success. | |
| 35 """ | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
36 if os.name == 'posix': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
37 _spawn_posix(cmd, search_path, dry_run=dry_run) |
| 11257 | 38 elif os.name == 'nt': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
39 _spawn_nt(cmd, search_path, dry_run=dry_run) |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
40 elif os.name == 'os2': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
41 _spawn_os2(cmd, search_path, dry_run=dry_run) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
42 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
43 raise DistutilsPlatformError, \ |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
44 "don't know how to spawn programs on platform '%s'" % os.name |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
45 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
46 # spawn () |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
47 |
| 11257 | 48 |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
49 def _nt_quote_args (args): |
| 14861 | 50 """Quote command-line arguments for DOS/Windows conventions: just |
| 51 wraps every argument which contains blanks in double quotes, and | |
| 52 returns a new argument list. | |
| 53 """ | |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
54 |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
55 # XXX this doesn't seem very robust to me -- but if the Windows guys |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
56 # say it'll work, I guess I'll have to accept it. (What if an arg |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
57 # contains quotes? What other magic characters, other than spaces, |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
58 # have to be escaped? Is there an escaping mechanism other than |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
59 # quoting?) |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
60 |
| 14861 | 61 for i in range(len(args)): |
| 62 if string.find(args[i], ' ') != -1: | |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
63 args[i] = '"%s"' % args[i] |
|
12058
c6cb0d266839
Duh, it helps if '_nt_quote_args()' actually returns the mutated list,
Greg Ward <gward@python.net>
parents:
12043
diff
changeset
|
64 return args |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
65 |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
66 def _spawn_nt (cmd, |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
67 search_path=1, |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
68 verbose=0, |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
69 dry_run=0): |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
70 |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
71 executable = cmd[0] |
| 14861 | 72 cmd = _nt_quote_args(cmd) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
73 if search_path: |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
74 # either we find one or it stays the same |
| 21267 | 75 executable = find_executable(executable) or executable |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
76 log.info(string.join([executable] + cmd[1:], ' ')) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
77 if not dry_run: |
|
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
78 # spawn for NT requires a full path to the .exe |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
79 try: |
| 14861 | 80 rc = os.spawnv(os.P_WAIT, executable, cmd) |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
81 except OSError, exc: |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
82 # this seems to happen when the command isn't found |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
83 raise DistutilsExecError, \ |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
84 "command '%s' failed: %s" % (cmd[0], exc[-1]) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
85 if rc != 0: |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
86 # and this reflects the command running but failing |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
87 raise DistutilsExecError, \ |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
88 "command '%s' failed with exit status %d" % (cmd[0], rc) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
89 |
| 21267 | 90 |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
91 def _spawn_os2 (cmd, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
92 search_path=1, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
93 verbose=0, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
94 dry_run=0): |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
95 |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
96 executable = cmd[0] |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
97 #cmd = _nt_quote_args(cmd) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
98 if search_path: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
99 # either we find one or it stays the same |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
100 executable = find_executable(executable) or executable |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
101 log.info(string.join([executable] + cmd[1:], ' ')) |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
102 if not dry_run: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
103 # spawnv for OS/2 EMX requires a full path to the .exe |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
104 try: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
105 rc = os.spawnv(os.P_WAIT, executable, cmd) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
106 except OSError, exc: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
107 # this seems to happen when the command isn't found |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
108 raise DistutilsExecError, \ |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
109 "command '%s' failed: %s" % (cmd[0], exc[-1]) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
110 if rc != 0: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
111 # and this reflects the command running but failing |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
112 print "command '%s' failed with exit status %d" % (cmd[0], rc) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
113 raise DistutilsExecError, \ |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
114 "command '%s' failed with exit status %d" % (cmd[0], rc) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
115 |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
116 |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
117 def _spawn_posix (cmd, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
118 search_path=1, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
119 verbose=0, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
120 dry_run=0): |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
121 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
122 log.info(string.join(cmd, ' ')) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
123 if dry_run: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
124 return |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
125 exec_fn = search_path and os.execvp or os.execv |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
126 |
| 14861 | 127 pid = os.fork() |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
128 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
129 if pid == 0: # in the child |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
130 try: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
131 #print "cmd[0] =", cmd[0] |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
132 #print "cmd =", cmd |
| 14861 | 133 exec_fn(cmd[0], cmd) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
134 except OSError, e: |
| 14861 | 135 sys.stderr.write("unable to execute %s: %s\n" % |
| 136 (cmd[0], e.strerror)) | |
| 137 os._exit(1) | |
| 21267 | 138 |
| 14861 | 139 sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) |
| 140 os._exit(1) | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
141 |
| 21267 | 142 |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
143 else: # in the parent |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
144 # Loop until the child either exits or is terminated by a signal |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
145 # (ie. keep waiting if it's merely stopped) |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
146 while 1: |
| 14861 | 147 (pid, status) = os.waitpid(pid, 0) |
| 148 if os.WIFSIGNALED(status): | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
149 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
150 "command '%s' terminated by signal %d" % \ |
| 14861 | 151 (cmd[0], os.WTERMSIG(status)) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
152 |
| 14861 | 153 elif os.WIFEXITED(status): |
| 154 exit_status = os.WEXITSTATUS(status) | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
155 if exit_status == 0: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
156 return # hey, it succeeded! |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
157 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
158 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
159 "command '%s' failed with exit status %d" % \ |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
160 (cmd[0], exit_status) |
| 21267 | 161 |
| 14861 | 162 elif os.WIFSTOPPED(status): |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
163 continue |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
164 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
165 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
166 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
167 "unknown error executing '%s': termination status %d" % \ |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
168 (cmd[0], status) |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
169 # _spawn_posix () |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
170 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
171 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
172 def find_executable(executable, path=None): |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
173 """Try to find 'executable' in the directories listed in 'path' (a |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
174 string listing directories separated by 'os.pathsep'; defaults to |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
175 os.environ['PATH']). Returns the complete filename or None if not |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
176 found. |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
177 """ |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
178 if path is None: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
179 path = os.environ['PATH'] |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
180 paths = string.split(path, os.pathsep) |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
181 (base, ext) = os.path.splitext(executable) |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
182 if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
183 executable = executable + '.exe' |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
184 if not os.path.isfile(executable): |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
185 for p in paths: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
186 f = os.path.join(p, executable) |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
187 if os.path.isfile(f): |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
188 # the file exists, we have a shot at spawn working |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
189 return f |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
190 return None |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
191 else: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
192 return executable |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
193 |
| 21267 | 194 # find_executable() |
