我需要在
Python中使用它自己的专用TTY在一个单独的进程中运行一个交互式Bash实例(我不能使用pexpect).
我使用了这个代码片段,我常见于类似的程序中使用:
master,slave = pty.openpty()
p = subprocess.Popen(["/bin/bash","-i"],stdin=slave,stdout=slave,stderr=slave)
os.close(slave)
x = os.read(master,1026)
print x
subprocess.Popen.kill(p)
os.close(master)
但是当我运行它时,我得到以下输出:
$./pty_try.py
bash: cannot set terminal process group (10790): Inappropriate ioctl for device
bash: no job control in this shell
运行的Strace显示一些错误:
...
readlink("/usr/bin/python2.7",0x7ffc8db02510,4096) = -1 EINVAL (Invalid argument)
...
ioctl(3,SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS,0x7ffc8db03590) = -1 ENOTTY (Inappropriate ioctl for device)
...
readlink("./pty_try.py",0