Python pty.CHILD Examples
The following are 4
code examples of pty.CHILD().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pty
, or try the search function
.
Example #1
Source File: linux_pty.py From TerminalView with MIT License | 5 votes |
def __init__(self, cmd, cwd): self._cmd_return_code = 0 self._cmd_kill_signal = 0 self._shell_pid, self._master_fd = pty.fork() if self._shell_pid == pty.CHILD: os.environ["TERM"] = "linux" os.chdir(cwd) os.execv(cmd[0], cmd)
Example #2
Source File: __init__.py From camr with GNU General Public License v2.0 | 5 votes |
def __fork_pty(self): '''This implements a substitute for the forkpty system call. This should be more portable than the pty.fork() function. Specifically, this should work on Solaris. Modified 10.06.05 by Geoff Marshall: Implemented __fork_pty() method to resolve the issue with Python's pty.fork() not supporting Solaris, particularly ssh. Based on patch to posixmodule.c authored by Noah Spurrier:: http://mail.python.org/pipermail/python-dev/2003-May/035281.html ''' parent_fd, child_fd = os.openpty() if parent_fd < 0 or child_fd < 0: raise ExceptionPexpect("Could not open with os.openpty().") pid = os.fork() if pid == pty.CHILD: # Child. os.close(parent_fd) self.__pty_make_controlling_tty(child_fd) os.dup2(child_fd, self.STDIN_FILENO) os.dup2(child_fd, self.STDOUT_FILENO) os.dup2(child_fd, self.STDERR_FILENO) else: # Parent. os.close(child_fd) return pid, parent_fd
Example #3
Source File: shell_logger.py From thefuck with MIT License | 5 votes |
def _spawn(shell, master_read): """Create a spawned process. Modified version of pty.spawn with terminal size support. """ pid, master_fd = pty.fork() if pid == pty.CHILD: os.execlp(shell, shell) try: mode = tty.tcgetattr(pty.STDIN_FILENO) tty.setraw(pty.STDIN_FILENO) restore = True except tty.error: # This is the same as termios.error restore = False _set_pty_size(master_fd) signal.signal(signal.SIGWINCH, lambda *_: _set_pty_size(master_fd)) try: pty._copy(master_fd, master_read, pty._read) except OSError: if restore: tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode) os.close(master_fd) return os.waitpid(pid, 0)[1]
Example #4
Source File: step_definitions.py From dockerpty with Apache License 2.0 | 5 votes |
def alloc_pty(ctx, f, *args, **kwargs): pid, fd = pty.fork() if pid == pty.CHILD: tty = os.ttyname(0) sys.stdin = open(tty, 'r') sys.stdout = open(tty, 'w') sys.stderr = open(tty, 'w') # alternative way of doing ^ is to do: # kwargs["stdout"] = open(tty, 'w') # kwargs["stderr"] = open(tty, 'w') # kwargs["stdin"] = open(tty, 'r') # Create a new client for the child process to avoid concurrency issues client = get_client() f(client, *args, **kwargs) sys.exit(0) else: ctx.pty = fd util.set_pty_size( ctx.pty, (ctx.rows, ctx.cols) ) ctx.pid = pid util.wait(ctx.pty, timeout=5) time.sleep(1) # give the terminal some time to print prompt # util.exit_code can be called only once ctx.exit_code = util.exit_code(ctx.pid, timeout=5) if ctx.exit_code != 0: raise Exception("child process did not finish correctly")