Create a spawned process.
(argv, master_read=_read, stdin_read=_read)
| 185 | i_buf += data |
| 186 | |
| 187 | def spawn(argv, master_read=_read, stdin_read=_read): |
| 188 | """Create a spawned process.""" |
| 189 | if isinstance(argv, str): |
| 190 | argv = (argv,) |
| 191 | sys.audit('pty.spawn', argv) |
| 192 | |
| 193 | pid, master_fd = fork() |
| 194 | if pid == CHILD: |
| 195 | os.execlp(argv[0], *argv) |
| 196 | |
| 197 | try: |
| 198 | mode = tcgetattr(STDIN_FILENO) |
| 199 | setraw(STDIN_FILENO) |
| 200 | restore = True |
| 201 | except tty.error: # This is the same as termios.error |
| 202 | restore = False |
| 203 | |
| 204 | try: |
| 205 | _copy(master_fd, master_read, stdin_read) |
| 206 | finally: |
| 207 | if restore: |
| 208 | tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode) |
| 209 | |
| 210 | close(master_fd) |
| 211 | return waitpid(pid, 0)[1] |