def __init__(self, cmd, raw_debug = None):
if os.name == "nt":
raise RuntimeError, "Windows does not support pseudo-terminal devices"
if cmd:
# Spawn the new process in a new PTY
self.exit_pipe, child_pipe = os.pipe()
self.exit_callback = None
pid, fd = pty.fork()
if pid == 0:
try:
os.environ["TERM"] = "xterm-256color"
if "PYTHONPATH" in os.environ:
del(os.environ["PYTHONPATH"])
if "LD_LIBRARY_PATH" in os.environ:
del(os.environ["LD_LIBRARY_PATH"])
if sys.platform == "darwin":
if "DYLD_LIBRARY_PATH" in os.environ:
del(os.environ["DYLD_LIBRARY_PATH"])
retval = subprocess.call(cmd, close_fds=True)
os.write(2, "\033[01;34mProcess has completed.\033[00m\n")
os.write(child_pipe, "t")
os._exit(retval)
except:
pass
os.write(2, "\033[01;31mCommand '" + cmd[0] + "' failed to execute.\033[00m\n")
os.write(child_pipe, "f")
os._exit(1)
os.close(child_pipe)
self.pid = pid
self.data_pipe = fd
else:
self.exit_pipe = -1
self.pid = -1
self.data_pipe = -1
self.rows = 25
self.cols = 80
self.term = TerminalEmulator(self.rows, self.cols)
self.raw_debug = raw_debug
self.completed = False
self.term.response_callback = self.send_input
if cmd:
# Initialize terminal settings
fcntl.ioctl(self.data_pipe, termios.TIOCSWINSZ, struct.pack("hhhh", self.rows, self.cols, 0, 0))
attribute = termios.tcgetattr(self.data_pipe)
termios.tcsetattr(self.data_pipe, termios.TCSAFLUSH, attribute)
else:
self.process_input("\033[01;33mEnter desired command arguments, then run again.\033[00m\r\n")
self.completed = True
评论列表
文章目录