os.fork and pty.fork
esnow at verio.net
Thu Jan 8 07:32:24 CET 2009
I am trying to wrap my head around an issue here that has to do with
running python without a tty. I use pexpect to connect to ssh and run
some commands. However, if my script runs from a process which I
forked using os.fork my pexpect spawn object can't open a good file
descriptor in which to run my ssh command, as far as I can tell.
pexpect uses pty.fork to fork the process, attach a tty, and run my
command in the child with os.exec.
When I go to expect something on the spawn object the read on the fd
of the child returns EOF, which indicates that the child's fd is
already closed before I did anything. This is the point at which I am
trying to make sense of things. pty.fork gave pexpect the child's fd
but does that fd actually go to a tty? Does the fact that my use of
pexpect happens in a process which is not running in a tty, as it was
generated from os.fork? It looks like pty.fork tries to use
os.forkpty but I am not sure how an existing tty plays in to getting a
new tty for the child process...
Any insight into os.fork and pty.fork would be great. Thanks.
More information about the Python-list