Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/spawn.py @ 51749:1408feec0084 3.0
Merged revisions 69798 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines
Merged revisions 69769,69776 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line
#5310, #3558: fix operator precedence table.
........
r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines
#5317: update IronPython URL.
........
................
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 20 Feb 2009 04:05:32 +0000 |
| parents | d0465e782b01 |
| children | 5e4d070565e7 |
| 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 |
|
11897
017e592c0fd2
Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents:
11665
diff
changeset
|
9 __revision__ = "$Id$" |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
11 import sys, os |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 from distutils.errors import * |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
13 from distutils import log |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
14 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
15 def spawn(cmd, search_path=1, verbose=0, dry_run=0): |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
16 """Run another program, specified as a command list 'cmd', in a new |
| 14861 | 17 process. 'cmd' is just the argument list for the new process, ie. |
| 18 cmd[0] is the program to run and cmd[1:] are the rest of its arguments. | |
| 19 There is no way to run a program with a name different from that of its | |
| 20 executable. | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
21 |
| 26324 | 22 If 'search_path' is true (the default), the system's executable |
| 23 search path will be used to find the program; otherwise, cmd[0] | |
| 24 must be the exact path to the executable. If 'dry_run' is true, | |
| 14861 | 25 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
|
26 |
| 14861 | 27 Raise DistutilsExecError if running the program fails in any way; just |
| 28 return on success. | |
| 29 """ | |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
30 if os.name == 'posix': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
31 _spawn_posix(cmd, search_path, dry_run=dry_run) |
| 11257 | 32 elif os.name == 'nt': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
33 _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
|
34 elif os.name == 'os2': |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21851
diff
changeset
|
35 _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
|
36 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
37 raise DistutilsPlatformError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
38 "don't know how to spawn programs on platform '%s'" % os.name) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
39 |
| 11257 | 40 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
41 def _nt_quote_args(args): |
| 14861 | 42 """Quote command-line arguments for DOS/Windows conventions: just |
| 43 wraps every argument which contains blanks in double quotes, and | |
| 44 returns a new argument list. | |
| 45 """ | |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
46 # 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
|
47 # 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
|
48 # 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
|
49 # 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
|
50 # quoting?) |
| 14861 | 51 for i in range(len(args)): |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
52 if args[i].find(' ') != -1: |
|
11933
68e0ef052815
Added '_nt_quote_args()' to deal with whitespace in command-line arguments
Greg Ward <gward@python.net>
parents:
11897
diff
changeset
|
53 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
|
54 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
|
55 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
56 def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0): |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
57 executable = cmd[0] |
| 14861 | 58 cmd = _nt_quote_args(cmd) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
59 if search_path: |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
60 # either we find one or it stays the same |
| 21267 | 61 executable = find_executable(executable) or executable |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
62 log.info(' '.join([executable] + cmd[1:])) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
63 if not dry_run: |
|
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
64 # 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
|
65 try: |
| 14861 | 66 rc = os.spawnv(os.P_WAIT, executable, cmd) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
33965
diff
changeset
|
67 except OSError as exc: |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
68 # this seems to happen when the command isn't found |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
69 raise DistutilsExecError( |
|
44542
d0465e782b01
Fix more exception slicing.
Georg Brandl <georg@python.org>
parents:
43026
diff
changeset
|
70 "command '%s' failed: %s" % (cmd[0], exc.args[-1])) |
|
11250
b3f1abd3027f
Patch from Perry Stoll: support for Windows.
Greg Ward <gward@python.net>
parents:
11198
diff
changeset
|
71 if rc != 0: |
|
11665
e998b350a4bb
Catch OSError from 'spawnv()' in '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
11257
diff
changeset
|
72 # and this reflects the command running but failing |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
73 raise DistutilsExecError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
74 "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
|
75 |
| 21267 | 76 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
77 def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0): |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
78 executable = cmd[0] |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
79 #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
|
80 if search_path: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
81 # either we find one or it stays the same |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
31586
diff
changeset
|
82 executable = find_executable(executable) or executable |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
83 log.info(' '.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
|
84 if not dry_run: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
85 # 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
|
86 try: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
87 rc = os.spawnv(os.P_WAIT, executable, cmd) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
33965
diff
changeset
|
88 except OSError as exc: |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
89 # this seems to happen when the command isn't found |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
90 raise DistutilsExecError( |
|
44542
d0465e782b01
Fix more exception slicing.
Georg Brandl <georg@python.org>
parents:
43026
diff
changeset
|
91 "command '%s' failed: %s" % (cmd[0], exc.args[-1])) |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
92 if rc != 0: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
93 # and this reflects the command running but failing |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
94 print("command '%s' failed with exit status %d" % (cmd[0], rc)) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
95 raise DistutilsExecError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
96 "command '%s' failed with exit status %d" % (cmd[0], rc)) |
|
21851
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 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
99 def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
100 log.info(' '.join(cmd)) |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
101 if dry_run: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
102 return |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
103 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
|
104 |
| 14861 | 105 pid = os.fork() |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
106 if pid == 0: # in the child |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
107 try: |
| 14861 | 108 exec_fn(cmd[0], cmd) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
33965
diff
changeset
|
109 except OSError as e: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
110 sys.stderr.write("unable to execute %s: %s\n" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
111 % (cmd[0], e.strerror)) |
| 14861 | 112 os._exit(1) |
| 21267 | 113 |
| 14861 | 114 sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) |
| 115 os._exit(1) | |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
116 else: # in the parent |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
117 # 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
|
118 # (ie. keep waiting if it's merely stopped) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
119 while True: |
|
31586
54685d9ffb87
Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents:
26324
diff
changeset
|
120 try: |
|
54685d9ffb87
Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents:
26324
diff
changeset
|
121 (pid, status) = os.waitpid(pid, 0) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
33965
diff
changeset
|
122 except OSError as exc: |
|
31586
54685d9ffb87
Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents:
26324
diff
changeset
|
123 import errno |
|
54685d9ffb87
Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents:
26324
diff
changeset
|
124 if exc.errno == errno.EINTR: |
|
54685d9ffb87
Make _spawn_posix be ready for EINTR. waitpid(2) can be interrupted
Hye-Shik Chang <hyeshik@gmail.com>
parents:
26324
diff
changeset
|
125 continue |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
126 raise DistutilsExecError( |
|
44542
d0465e782b01
Fix more exception slicing.
Georg Brandl <georg@python.org>
parents:
43026
diff
changeset
|
127 "command '%s' failed: %s" % (cmd[0], exc.args[-1])) |
| 14861 | 128 if os.WIFSIGNALED(status): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
129 raise DistutilsExecError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
130 "command '%s' terminated by signal %d" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
131 % (cmd[0], os.WTERMSIG(status))) |
| 14861 | 132 elif os.WIFEXITED(status): |
| 133 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
|
134 if exit_status == 0: |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
135 return # hey, it succeeded! |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
136 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
137 raise DistutilsExecError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
138 "command '%s' failed with exit status %d" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
139 % (cmd[0], exit_status)) |
| 14861 | 140 elif os.WIFSTOPPED(status): |
|
11198
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
141 continue |
|
e8b24cd17df2
Module to spawn sub-commands in a platform-independent way.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
142 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
143 raise DistutilsExecError( |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
144 "unknown error executing '%s': termination status %d" |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41480
diff
changeset
|
145 % (cmd[0], status)) |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
146 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
147 |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
148 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
|
149 """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
|
150 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
|
151 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
|
152 found. |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
153 """ |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
154 if path is None: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
155 path = os.environ['PATH'] |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
156 paths = path.split(os.pathsep) |
|
13803
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
157 (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
|
158 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
|
159 executable = executable + '.exe' |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
160 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
|
161 for p in paths: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
162 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
|
163 if os.path.isfile(f): |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
164 # 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
|
165 return f |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
166 return None |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
167 else: |
|
e8b22bc88d95
Rene Liebscher: factor 'find_executable()' out of '_spawn_nt()'.
Greg Ward <gward@python.net>
parents:
12058
diff
changeset
|
168 return executable |
