equal
deleted
inserted
replaced
3 |
3 |
4 # subset of subprocess built-in module using posix_spawn rather than fork. |
4 # subset of subprocess built-in module using posix_spawn rather than fork. |
5 |
5 |
6 |
6 |
7 |
7 |
8 import os |
8 import os, sys |
9 import signal |
9 import signal |
10 import shlex |
10 import shlex |
11 import posix_spawn |
11 import posix_spawn |
12 |
12 |
13 PIPE = "42" |
13 PIPE = "42" |
14 |
14 |
|
15 fsencoding = sys.getfilesystemencoding() |
15 |
16 |
16 class Popen(object): |
17 class Popen(object): |
17 def __init__(self, args, stdin=None, stdout=None): |
18 def __init__(self, args, stdin=None, stdout=None): |
18 self.returncode = None |
19 self.returncode = None |
19 self.stdout = None |
20 self.stdout = None |
32 p2cread, p2cwrite = os.pipe() |
33 p2cread, p2cwrite = os.pipe() |
33 # attach child's stdin to reading en of p2c pipe |
34 # attach child's stdin to reading en of p2c pipe |
34 file_actions.add_dup2(p2cread, 0) |
35 file_actions.add_dup2(p2cread, 0) |
35 # close other end |
36 # close other end |
36 file_actions.add_close(p2cwrite) |
37 file_actions.add_close(p2cwrite) |
|
38 args = [s.encode(fsencoding) for s in args if type(s)==str] |
37 self.pid = posix_spawn.posix_spawnp(args[0], args, file_actions=file_actions) |
39 self.pid = posix_spawn.posix_spawnp(args[0], args, file_actions=file_actions) |
38 if stdout is not None: |
40 if stdout is not None: |
39 self.stdout = os.fdopen(c2pread) |
41 self.stdout = os.fdopen(c2pread) |
40 os.close(c2pwrite) |
42 os.close(c2pwrite) |
41 if stdin is not None: |
43 if stdin is not None: |