blob: bda12af9f7cb7537998bb517f0d1b0da42e53b4b [file] [log] [blame]
Ka-Ping Yeefeb67192001-03-02 23:31:431r"""OS routines for Mac, DOS, NT, or Posix depending on what system we're on.
Guido van Rossum31104f41992-01-14 18:28:362
Guido van Rossum54f22ed2000-02-04 15:10:343This exports:
Guido van Rossum4b8c6ea2000-02-04 15:39:304 - all functions from posix, nt, dos, os2, mac, or ce, e.g. unlink, stat, etc.
5 - os.path is one of the modules posixpath, ntpath, macpath, or dospath
Guido van Rossumd74fb6b2001-03-02 06:43:496 - os.name is 'posix', 'nt', 'dos', 'os2', 'mac', 'ce' or 'riscos'
Guido van Rossum54f22ed2000-02-04 15:10:347 - os.curdir is a string representing the current directory ('.' or ':')
8 - os.pardir is a string representing the parent directory ('..' or '::')
9 - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
Guido van Rossum4b8c6ea2000-02-04 15:39:3010 - os.altsep is the alternate pathname separator (None or '/')
Guido van Rossum54f22ed2000-02-04 15:10:3411 - os.pathsep is the component separator used in $PATH etc
Guido van Rossum4b8c6ea2000-02-04 15:39:3012 - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
Guido van Rossum54f22ed2000-02-04 15:10:3413 - os.defpath is the default search path for executables
Guido van Rossum31104f41992-01-14 18:28:3614
Guido van Rossum54f22ed2000-02-04 15:10:3415Programs that import and use 'os' stand a better chance of being
16portable between different platforms. Of course, they must then
17only use functions that are defined by all platforms (e.g., unlink
18and opendir), and leave all pathname manipulation to os.path
19(e.g., split and join).
20"""
Guido van Rossum31104f41992-01-14 18:28:3621
Skip Montanaro269b83b2001-02-06 01:07:0222#'
23
Guido van Rossum2979b011994-08-01 11:18:3024import sys
Guido van Rossuma28dab51997-08-29 22:36:4725
26_names = sys.builtin_module_names
27
28altsep = None
29
Skip Montanaro6c0a0e12001-02-28 01:00:5830__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
31 "defpath", "name"]
Skip Montanaro269b83b2001-02-06 01:07:0232
33def _get_exports_list(module):
34 try:
35 return list(module.__all__)
36 except AttributeError:
37 return [n for n in dir(module) if n[0] != '_']
38
Guido van Rossuma28dab51997-08-29 22:36:4739if 'posix' in _names:
Guido van Rossum61de0ac1997-12-05 21:24:3040 name = 'posix'
Guido van Rossume9387ea1998-05-22 15:26:0441 linesep = '\n'
Guido van Rossum61de0ac1997-12-05 21:24:3042 curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':'
43 defpath = ':/bin:/usr/bin'
44 from posix import *
45 try:
46 from posix import _exit
47 except ImportError:
48 pass
49 import posixpath
50 path = posixpath
51 del posixpath
Skip Montanaro269b83b2001-02-06 01:07:0252
53 import posix
54 __all__.extend(_get_exports_list(posix))
55 del posix
56
Guido van Rossuma28dab51997-08-29 22:36:4757elif 'nt' in _names:
Guido van Rossum61de0ac1997-12-05 21:24:3058 name = 'nt'
Guido van Rossume9387ea1998-05-22 15:26:0459 linesep = '\r\n'
Guido van Rossum61de0ac1997-12-05 21:24:3060 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
61 defpath = '.;C:\\bin'
62 from nt import *
Guido van Rossumfb801e71999-02-22 15:40:3463 for i in ['_exit']:
Guido van Rossum67c65b21999-02-01 23:52:2964 try:
65 exec "from nt import " + i
66 except ImportError:
67 pass
Guido van Rossum61de0ac1997-12-05 21:24:3068 import ntpath
69 path = ntpath
70 del ntpath
Skip Montanaro269b83b2001-02-06 01:07:0271
72 import nt
73 __all__.extend(_get_exports_list(nt))
74 del nt
75
Guido van Rossuma28dab51997-08-29 22:36:4776elif 'dos' in _names:
Guido van Rossum61de0ac1997-12-05 21:24:3077 name = 'dos'
Guido van Rossume9387ea1998-05-22 15:26:0478 linesep = '\r\n'
Guido van Rossum61de0ac1997-12-05 21:24:3079 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
80 defpath = '.;C:\\bin'
81 from dos import *
82 try:
83 from dos import _exit
84 except ImportError:
85 pass
86 import dospath
87 path = dospath
88 del dospath
Skip Montanaro269b83b2001-02-06 01:07:0289
90 import dos
91 __all__.extend(_get_exports_list(dos))
92 del dos
93
Guido van Rossum8e9ebfd1997-11-22 21:53:4894elif 'os2' in _names:
Guido van Rossum61de0ac1997-12-05 21:24:3095 name = 'os2'
Guido van Rossume9387ea1998-05-22 15:26:0496 linesep = '\r\n'
Guido van Rossum61de0ac1997-12-05 21:24:3097 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
98 defpath = '.;C:\\bin'
99 from os2 import *
100 try:
101 from os2 import _exit
102 except ImportError:
103 pass
104 import ntpath
105 path = ntpath
106 del ntpath
Skip Montanaro269b83b2001-02-06 01:07:02107
108 import os2
109 __all__.extend(_get_exports_list(os2))
110 del os2
111
Guido van Rossuma28dab51997-08-29 22:36:47112elif 'mac' in _names:
Guido van Rossum61de0ac1997-12-05 21:24:30113 name = 'mac'
Guido van Rossume9387ea1998-05-22 15:26:04114 linesep = '\r'
Guido van Rossum61de0ac1997-12-05 21:24:30115 curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
116 defpath = ':'
117 from mac import *
118 try:
119 from mac import _exit
120 except ImportError:
121 pass
122 import macpath
123 path = macpath
124 del macpath
Skip Montanaro269b83b2001-02-06 01:07:02125
126 import mac
127 __all__.extend(_get_exports_list(mac))
128 del mac
129
Guido van Rossum18df5d41999-06-11 01:37:27130elif 'ce' in _names:
131 name = 'ce'
132 linesep = '\r\n'
133 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
134 defpath = '\\Windows'
135 from ce import *
136 for i in ['_exit']:
137 try:
138 exec "from ce import " + i
139 except ImportError:
140 pass
141 # We can use the standard Windows path.
142 import ntpath
143 path = ntpath
144 del ntpath
Skip Montanaro269b83b2001-02-06 01:07:02145
146 import ce
147 __all__.extend(_get_exports_list(ce))
148 del ce
149
Guido van Rossumd74fb6b2001-03-02 06:43:49150elif 'riscos' in _names:
151 name = 'riscos'
152 linesep = '\n'
153 curdir = '@'; pardir = '^'; sep = '.'; pathsep = ','
154 defpath = '<Run$Dir>'
155 from riscos import *
156 try:
157 from riscos import _exit
158 except ImportError:
159 pass
160 import riscospath
161 path = riscospath
162 del riscospath
Guido van Rossumd74fb6b2001-03-02 06:43:49163
164 import riscos
165 __all__.extend(_get_exports_list(riscos))
Skip Montanaro81e4b1c2001-03-06 15:26:07166 del riscos
Guido van Rossumd74fb6b2001-03-02 06:43:49167
Guido van Rossum2979b011994-08-01 11:18:30168else:
Guido van Rossum61de0ac1997-12-05 21:24:30169 raise ImportError, 'no os specific module found'
Guido van Rossume65cce51993-11-08 15:05:21170
Skip Montanaro269b83b2001-02-06 01:07:02171__all__.append("path")
172
Guido van Rossuma28dab51997-08-29 22:36:47173del _names
174
Fred Drake02379091999-01-19 16:05:13175sys.modules['os.path'] = path
176
Skip Montanaro269b83b2001-02-06 01:07:02177#'
178
Guido van Rossum4def7de1998-07-24 20:48:03179# Super directory utilities.
180# (Inspired by Eric Raymond; the doc strings are mostly his)
181
182def makedirs(name, mode=0777):
183 """makedirs(path [, mode=0777]) -> None
184
185 Super-mkdir; create a leaf directory and all intermediate ones.
186 Works like mkdir, except that any intermediate path segment (not
187 just the rightmost) will be created if it does not exist. This is
188 recursive.
189
190 """
191 head, tail = path.split(name)
Fred Drake9f2550f2000-07-25 15:16:40192 if not tail:
193 head, tail = path.split(head)
Guido van Rossum4def7de1998-07-24 20:48:03194 if head and tail and not path.exists(head):
195 makedirs(head, mode)
196 mkdir(name, mode)
197
198def removedirs(name):
199 """removedirs(path) -> None
200
201 Super-rmdir; remove a leaf directory and empty all intermediate
202 ones. Works like rmdir except that, if the leaf directory is
203 successfully removed, directories corresponding to rightmost path
204 segments will be pruned way until either the whole path is
205 consumed or an error occurs. Errors during this latter phase are
206 ignored -- they generally mean that a directory was not empty.
207
208 """
209 rmdir(name)
210 head, tail = path.split(name)
Fred Drake9f2550f2000-07-25 15:16:40211 if not tail:
212 head, tail = path.split(head)
Guido van Rossum4def7de1998-07-24 20:48:03213 while head and tail:
214 try:
215 rmdir(head)
216 except error:
217 break
218 head, tail = path.split(head)
219
220def renames(old, new):
221 """renames(old, new) -> None
222
223 Super-rename; create directories as necessary and delete any left
224 empty. Works like rename, except creation of any intermediate
225 directories needed to make the new pathname good is attempted
226 first. After the rename, directories corresponding to rightmost
227 path segments of the old name will be pruned way until either the
228 whole path is consumed or a nonempty directory is found.
229
230 Note: this function can fail with the new directory structure made
231 if you lack permissions needed to unlink the leaf directory or
232 file.
233
234 """
235 head, tail = path.split(new)
236 if head and tail and not path.exists(head):
237 makedirs(head)
238 rename(old, new)
239 head, tail = path.split(old)
240 if head and tail:
241 try:
242 removedirs(head)
243 except error:
244 pass
245
Skip Montanaro269b83b2001-02-06 01:07:02246__all__.extend(["makedirs", "removedirs", "renames"])
247
Guido van Rossuma28dab51997-08-29 22:36:47248# Make sure os.environ exists, at least
249try:
Guido van Rossum61de0ac1997-12-05 21:24:30250 environ
Guido van Rossuma28dab51997-08-29 22:36:47251except NameError:
Guido van Rossum61de0ac1997-12-05 21:24:30252 environ = {}
Guido van Rossuma28dab51997-08-29 22:36:47253
Guido van Rossume65cce51993-11-08 15:05:21254def execl(file, *args):
Guido van Rossum7da3cc52000-04-25 10:53:22255 """execl(file, *args)
256
257 Execute the executable file with argument list args, replacing the
258 current process. """
Guido van Rossum61de0ac1997-12-05 21:24:30259 execv(file, args)
Guido van Rossume65cce51993-11-08 15:05:21260
261def execle(file, *args):
Guido van Rossum7da3cc52000-04-25 10:53:22262 """execle(file, *args, env)
263
264 Execute the executable file with argument list args and
265 environment env, replacing the current process. """
Guido van Rossum61de0ac1997-12-05 21:24:30266 env = args[-1]
267 execve(file, args[:-1], env)
Guido van Rossume65cce51993-11-08 15:05:21268
269def execlp(file, *args):
Guido van Rossum7da3cc52000-04-25 10:53:22270 """execlp(file, *args)
271
272 Execute the executable file (which is searched for along $PATH)
273 with argument list args, replacing the current process. """
Guido van Rossum61de0ac1997-12-05 21:24:30274 execvp(file, args)
Guido van Rossume65cce51993-11-08 15:05:21275
Guido van Rossum030afb11995-03-14 17:27:18276def execlpe(file, *args):
Guido van Rossum7da3cc52000-04-25 10:53:22277 """execlpe(file, *args, env)
278
279 Execute the executable file (which is searched for along $PATH)
280 with argument list args and environment env, replacing the current
Tim Peters2344fae2001-01-15 00:50:52281 process. """
Guido van Rossum61de0ac1997-12-05 21:24:30282 env = args[-1]
283 execvpe(file, args[:-1], env)
Guido van Rossum030afb11995-03-14 17:27:18284
Guido van Rossume65cce51993-11-08 15:05:21285def execvp(file, args):
Guido van Rossum7da3cc52000-04-25 10:53:22286 """execp(file, args)
287
288 Execute the executable file (which is searched for along $PATH)
289 with argument list args, replacing the current process.
Thomas Wouters7e474022000-07-16 12:04:32290 args may be a list or tuple of strings. """
Guido van Rossum61de0ac1997-12-05 21:24:30291 _execvpe(file, args)
Guido van Rossum030afb11995-03-14 17:27:18292
293def execvpe(file, args, env):
Guido van Rossumb6e835c2002-09-04 11:41:51294 """execvpe(file, args, env)
Guido van Rossum7da3cc52000-04-25 10:53:22295
296 Execute the executable file (which is searched for along $PATH)
297 with argument list args and environment env , replacing the
298 current process.
Tim Peters2344fae2001-01-15 00:50:52299 args may be a list or tuple of strings. """
Guido van Rossum61de0ac1997-12-05 21:24:30300 _execvpe(file, args, env)
Guido van Rossum030afb11995-03-14 17:27:18301
Skip Montanaro269b83b2001-02-06 01:07:02302__all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
303
Guido van Rossum5a2ca931999-11-02 13:27:32304def _execvpe(file, args, env=None):
Guido van Rossumd31a8032002-08-08 19:46:52305 from errno import ENOENT, ENOTDIR
306
Guido van Rossum5a2ca931999-11-02 13:27:32307 if env is not None:
Guido van Rossum61de0ac1997-12-05 21:24:30308 func = execve
309 argrest = (args, env)
310 else:
311 func = execv
312 argrest = (args,)
313 env = environ
Guido van Rossumd31a8032002-08-08 19:46:52314
Guido van Rossum61de0ac1997-12-05 21:24:30315 head, tail = path.split(file)
316 if head:
317 apply(func, (file,) + argrest)
318 return
319 if env.has_key('PATH'):
320 envpath = env['PATH']
321 else:
322 envpath = defpath
Guido van Rossum965fdae2000-04-04 19:50:04323 PATH = envpath.split(pathsep)
Guido van Rossumb6e835c2002-09-04 11:41:51324 saved_exc = None
325 saved_tb = None
Guido van Rossum61de0ac1997-12-05 21:24:30326 for dir in PATH:
327 fullname = path.join(dir, file)
328 try:
329 apply(func, (fullname,) + argrest)
Guido van Rossumb6e835c2002-09-04 11:41:51330 except error, e:
331 tb = sys.exc_info()[2]
332 if (e.errno != ENOENT and e.errno != ENOTDIR
333 and saved_exc is None):
334 saved_exc = e
335 saved_tb = tb
336 if saved_exc:
337 raise error, saved_exc, saved_tb
338 raise error, e, tb
Guido van Rossumd74fb6b2001-03-02 06:43:49339
Martin v. Löwisa90f4382001-03-07 09:05:45340# Change environ to automatically call putenv() if it exists
341try:
342 # This will fail if there's no putenv
343 putenv
344except NameError:
345 pass
346else:
347 import UserDict
Guido van Rossum3b8e20d1996-07-24 00:55:17348
Martin v. Löwisa90f4382001-03-07 09:05:45349 if name == "riscos":
350 # On RISC OS, all env access goes through getenv and putenv
351 from riscosenviron import _Environ
352 elif name in ('os2', 'nt', 'dos'): # Where Env Var Names Must Be UPPERCASE
Guido van Rossumda4d6da1998-08-04 16:01:23353 # But we store them as upper case
Guido van Rossum61de0ac1997-12-05 21:24:30354 class _Environ(UserDict.UserDict):
355 def __init__(self, environ):
356 UserDict.UserDict.__init__(self)
Guido van Rossumda4d6da1998-08-04 16:01:23357 data = self.data
Guido van Rossumda4d6da1998-08-04 16:01:23358 for k, v in environ.items():
Guido van Rossum965fdae2000-04-04 19:50:04359 data[k.upper()] = v
Guido van Rossum61de0ac1997-12-05 21:24:30360 def __setitem__(self, key, item):
Guido van Rossum61de0ac1997-12-05 21:24:30361 putenv(key, item)
Guido van Rossum965fdae2000-04-04 19:50:04362 self.data[key.upper()] = item
Guido van Rossum61de0ac1997-12-05 21:24:30363 def __getitem__(self, key):
Guido van Rossum965fdae2000-04-04 19:50:04364 return self.data[key.upper()]
365 def __delitem__(self, key):
366 del self.data[key.upper()]
Guido van Rossumb46413f1999-05-03 15:23:24367 def has_key(self, key):
Guido van Rossum965fdae2000-04-04 19:50:04368 return self.data.has_key(key.upper())
369 def get(self, key, failobj=None):
370 return self.data.get(key.upper(), failobj)
371 def update(self, dict):
372 for k, v in dict.items():
373 self[k] = v
Guido van Rossum3b8e20d1996-07-24 00:55:17374
Guido van Rossum61de0ac1997-12-05 21:24:30375 else: # Where Env Var Names Can Be Mixed Case
376 class _Environ(UserDict.UserDict):
377 def __init__(self, environ):
378 UserDict.UserDict.__init__(self)
379 self.data = environ
Guido van Rossum61de0ac1997-12-05 21:24:30380 def __setitem__(self, key, item):
381 putenv(key, item)
382 self.data[key] = item
Guido van Rossum965fdae2000-04-04 19:50:04383 def update(self, dict):
384 for k, v in dict.items():
385 self[k] = v
Guido van Rossum61de0ac1997-12-05 21:24:30386
387 environ = _Environ(environ)
Guido van Rossum5a2ca931999-11-02 13:27:32388
Guido van Rossumd74fb6b2001-03-02 06:43:49389 def getenv(key, default=None):
390 """Get an environment variable, return None if it doesn't exist.
391 The optional second argument can specify an alternate default."""
392 return environ.get(key, default)
393 __all__.append("getenv")
Guido van Rossum5a2ca931999-11-02 13:27:32394
395def _exists(name):
396 try:
397 eval(name)
398 return 1
399 except NameError:
400 return 0
401
402# Supply spawn*() (probably only for Unix)
403if _exists("fork") and not _exists("spawnv") and _exists("execv"):
404
405 P_WAIT = 0
406 P_NOWAIT = P_NOWAITO = 1
407
408 # XXX Should we support P_DETACH? I suppose it could fork()**2
409 # and close the std I/O streams. Also, P_OVERLAY is the same
410 # as execv*()?
411
412 def _spawnvef(mode, file, args, env, func):
413 # Internal helper; func is the exec*() function to use
414 pid = fork()
415 if not pid:
416 # Child
417 try:
418 if env is None:
419 func(file, args)
420 else:
421 func(file, args, env)
422 except:
423 _exit(127)
424 else:
425 # Parent
426 if mode == P_NOWAIT:
427 return pid # Caller is responsible for waiting!
428 while 1:
429 wpid, sts = waitpid(pid, 0)
430 if WIFSTOPPED(sts):
431 continue
432 elif WIFSIGNALED(sts):
433 return -WTERMSIG(sts)
434 elif WIFEXITED(sts):
435 return WEXITSTATUS(sts)
436 else:
437 raise error, "Not stopped, signaled or exited???"
438
439 def spawnv(mode, file, args):
Guido van Rossume0cd2912000-04-21 18:35:36440 """spawnv(mode, file, args) -> integer
441
442Execute file with arguments from args in a subprocess.
443If mode == P_NOWAIT return the pid of the process.
444If mode == P_WAIT return the process's exit code if it exits normally;
Tim Peters2344fae2001-01-15 00:50:52445otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32446 return _spawnvef(mode, file, args, None, execv)
447
448 def spawnve(mode, file, args, env):
Guido van Rossume0cd2912000-04-21 18:35:36449 """spawnve(mode, file, args, env) -> integer
450
451Execute file with arguments from args in a subprocess with the
452specified environment.
453If mode == P_NOWAIT return the pid of the process.
454If mode == P_WAIT return the process's exit code if it exits normally;
455otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32456 return _spawnvef(mode, file, args, env, execve)
457
Guido van Rossumdd7cbbf1999-11-02 20:44:07458 # Note: spawnvp[e] is't currently supported on Windows
459
460 def spawnvp(mode, file, args):
Guido van Rossume0cd2912000-04-21 18:35:36461 """spawnvp(mode, file, args) -> integer
462
463Execute file (which is looked for along $PATH) with arguments from
464args in a subprocess.
465If mode == P_NOWAIT return the pid of the process.
466If mode == P_WAIT return the process's exit code if it exits normally;
467otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossumdd7cbbf1999-11-02 20:44:07468 return _spawnvef(mode, file, args, None, execvp)
469
470 def spawnvpe(mode, file, args, env):
Guido van Rossume0cd2912000-04-21 18:35:36471 """spawnvpe(mode, file, args, env) -> integer
472
473Execute file (which is looked for along $PATH) with arguments from
474args in a subprocess with the supplied environment.
475If mode == P_NOWAIT return the pid of the process.
476If mode == P_WAIT return the process's exit code if it exits normally;
477otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossumdd7cbbf1999-11-02 20:44:07478 return _spawnvef(mode, file, args, env, execvpe)
479
480if _exists("spawnv"):
481 # These aren't supplied by the basic Windows code
482 # but can be easily implemented in Python
Guido van Rossum5a2ca931999-11-02 13:27:32483
484 def spawnl(mode, file, *args):
Guido van Rossume0cd2912000-04-21 18:35:36485 """spawnl(mode, file, *args) -> integer
486
487Execute file with arguments from args in a subprocess.
488If mode == P_NOWAIT return the pid of the process.
489If mode == P_WAIT return the process's exit code if it exits normally;
490otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32491 return spawnv(mode, file, args)
492
493 def spawnle(mode, file, *args):
Guido van Rossume0cd2912000-04-21 18:35:36494 """spawnle(mode, file, *args, env) -> integer
495
496Execute file with arguments from args in a subprocess with the
497supplied environment.
498If mode == P_NOWAIT return the pid of the process.
499If mode == P_WAIT return the process's exit code if it exits normally;
500otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32501 env = args[-1]
502 return spawnve(mode, file, args[:-1], env)
503
Guido van Rossumdd7cbbf1999-11-02 20:44:07504if _exists("spawnvp"):
505 # At the moment, Windows doesn't implement spawnvp[e],
506 # so it won't have spawnlp[e] either.
Guido van Rossum5a2ca931999-11-02 13:27:32507 def spawnlp(mode, file, *args):
Guido van Rossume0cd2912000-04-21 18:35:36508 """spawnlp(mode, file, *args, env) -> integer
509
510Execute file (which is looked for along $PATH) with arguments from
511args in a subprocess with the supplied environment.
512If mode == P_NOWAIT return the pid of the process.
513If mode == P_WAIT return the process's exit code if it exits normally;
514otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32515 return spawnvp(mode, file, args)
516
517 def spawnlpe(mode, file, *args):
Guido van Rossume0cd2912000-04-21 18:35:36518 """spawnlpe(mode, file, *args, env) -> integer
519
520Execute file (which is looked for along $PATH) with arguments from
521args in a subprocess with the supplied environment.
522If mode == P_NOWAIT return the pid of the process.
523If mode == P_WAIT return the process's exit code if it exits normally;
524otherwise return -SIG, where SIG is the signal that killed it. """
Guido van Rossum5a2ca931999-11-02 13:27:32525 env = args[-1]
526 return spawnvpe(mode, file, args[:-1], env)
Guido van Rossume0cd2912000-04-21 18:35:36527
528
Skip Montanaro269b83b2001-02-06 01:07:02529 __all__.extend(["spawnlp","spawnlpe","spawnv", "spawnve","spawnvp",
530 "spawnvpe","spawnl","spawnle",])
531
532
Guido van Rossumd9a8e962000-09-19 03:04:52533# Supply popen2 etc. (for Unix)
534if _exists("fork"):
535 if not _exists("popen2"):
536 def popen2(cmd, mode="t", bufsize=-1):
Guido van Rossumd9a8e962000-09-19 03:04:52537 import popen2
538 stdout, stdin = popen2.popen2(cmd, bufsize)
539 return stdin, stdout
Skip Montanaro269b83b2001-02-06 01:07:02540 __all__.append("popen2")
Fred Drake31f182e2000-08-28 17:20:05541
Guido van Rossumd9a8e962000-09-19 03:04:52542 if not _exists("popen3"):
543 def popen3(cmd, mode="t", bufsize=-1):
Guido van Rossumd9a8e962000-09-19 03:04:52544 import popen2
545 stdout, stdin, stderr = popen2.popen3(cmd, bufsize)
546 return stdin, stdout, stderr
Skip Montanaro269b83b2001-02-06 01:07:02547 __all__.append("popen3")
Fred Drake20af3172000-09-28 19:10:56548
549 if not _exists("popen4"):
550 def popen4(cmd, mode="t", bufsize=-1):
551 import popen2
552 stdout, stdin = popen2.popen4(cmd, bufsize)
553 return stdin, stdout
Skip Montanaro269b83b2001-02-06 01:07:02554 __all__.append("popen4")