Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/spawn.py @ 22360:c8a6ea00a9e1 legacy-trunk
restructure a bit to not rely on test case execution ordering
add test case for bug #482460
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Sun, 17 Mar 2002 23:03:42 +0000 |
| parents | e0fc286d57a4 |
| children | ca87119255eb |
| 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 * |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
15 |
|
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 | |
| 30 exact path to the executable. If 'verbose' is true, a one-line summary | |
| 31 of the command will be printed before it is run. If 'dry_run' is true, | |
| 32 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
|
33 |
| 14861 | 34 Raise DistutilsExecError if running the program fails in any way; just |
| 35 return on success. | |
| 36 """ | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
37 if os.name == 'posix': |
| 14861 | 38 _spawn_posix(cmd, search_path, verbose, dry_run) |
| 11257 | 39 elif os.name == 'nt': |
| 14861 | 40 _spawn_nt(cmd, search_path, verbose, dry_run) |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
41 elif os.name == 'os2': |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
42 _spawn_os2(cmd, search_path, verbose, dry_run) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
43 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
44 raise DistutilsPlatformError, \ |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
45 "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
|
46 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
47 # spawn () |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
48 |
| 11257 | 49 |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
50 def _nt_quote_args (args): |
| 14861 | 51 """Quote command-line arguments for DOS/Windows conventions: just |
| 52 wraps every argument which contains blanks in double quotes, and | |
| 53 returns a new argument list. | |
| 54 """ | |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
55 |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
56 # 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
|
57 # 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
|
58 # 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
|
59 # 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
|
60 # quoting?) |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
61 |
| 14861 | 62 for i in range(len(args)): |
| 63 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
|
64 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
|
65 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
|
66 |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
67 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
|
68 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
|
69 verbose=0, |
|
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
70 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
|
71 |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
72 executable = cmd[0] |
| 14861 | 73 cmd = _nt_quote_args(cmd) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
74 if search_path: |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
75 # either we find one or it stays the same |
| 21267 | 76 executable = find_executable(executable) or executable |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
77 if verbose: |
| 14861 | 78 print string.join([executable] + cmd[1:], ' ') |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
79 if not dry_run: |
|
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
80 # 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
|
81 try: |
| 14861 | 82 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
|
83 except OSError, exc: |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
84 # 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
|
85 raise DistutilsExecError, \ |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
86 "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
|
87 if rc != 0: |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
88 # 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
|
89 raise DistutilsExecError, \ |
|
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
90 "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
|
91 |
| 21267 | 92 |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
93 def _spawn_os2 (cmd, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
94 search_path=1, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
95 verbose=0, |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
96 dry_run=0): |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
97 |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
98 executable = cmd[0] |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
99 #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
|
100 if search_path: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
101 # 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
|
102 executable = find_executable(executable) or executable |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
103 if verbose: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
104 print string.join([executable] + cmd[1:], ' ') |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
105 if not dry_run: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
106 # 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
|
107 try: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
108 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
|
109 except OSError, exc: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
110 # 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
|
111 raise DistutilsExecError, \ |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
112 "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
|
113 if rc != 0: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
114 # 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
|
115 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
|
116 raise DistutilsExecError, \ |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
117 "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
|
118 |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
119 |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
120 def _spawn_posix (cmd, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
121 search_path=1, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
122 verbose=0, |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
123 dry_run=0): |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
124 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
125 if verbose: |
| 14861 | 126 print string.join(cmd, ' ') |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
127 if dry_run: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
128 return |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
129 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
|
130 |
| 14861 | 131 pid = os.fork() |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
132 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
133 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
|
134 try: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
135 #print "cmd[0] =", cmd[0] |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
136 #print "cmd =", cmd |
| 14861 | 137 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
|
138 except OSError, e: |
| 14861 | 139 sys.stderr.write("unable to execute %s: %s\n" % |
| 140 (cmd[0], e.strerror)) | |
| 141 os._exit(1) | |
| 21267 | 142 |
| 14861 | 143 sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) |
| 144 os._exit(1) | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
145 |
| 21267 | 146 |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
147 else: # in the parent |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
148 # 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
|
149 # (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
|
150 while 1: |
| 14861 | 151 (pid, status) = os.waitpid(pid, 0) |
| 152 if os.WIFSIGNALED(status): | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
153 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
154 "command '%s' terminated by signal %d" % \ |
| 14861 | 155 (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
|
156 |
| 14861 | 157 elif os.WIFEXITED(status): |
| 158 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
|
159 if exit_status == 0: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
160 return # hey, it succeeded! |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
161 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
162 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
163 "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
|
164 (cmd[0], exit_status) |
| 21267 | 165 |
| 14861 | 166 elif os.WIFSTOPPED(status): |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
167 continue |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
168 |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
169 else: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
170 raise DistutilsExecError, \ |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
171 "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
|
172 (cmd[0], status) |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
173 # _spawn_posix () |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
174 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
175 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
176 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
|
177 """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
|
178 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
|
179 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
|
180 found. |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
181 """ |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
182 if path is None: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
183 path = os.environ['PATH'] |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
184 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
|
185 (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
|
186 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
|
187 executable = executable + '.exe' |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
188 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
|
189 for p in paths: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
190 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
|
191 if os.path.isfile(f): |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
192 # 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
|
193 return f |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
194 return None |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
195 else: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
196 return executable |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
197 |
| 21267 | 198 # find_executable() |
