TerminalProcess.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:OSPTF 作者: xSploited 项目源码 文件源码
def restart(self, cmd):
        if not self.completed:
            self.process_input("\n\033[01;31mProcess killed.\033[00m\r\n")
            os.kill(self.pid, signal.SIGHUP)
            thread = self.thread
            thread.stop()
            while thread.alive:
                QCoreApplication.processEvents()

        self.exit_pipe, child_pipe = os.pipe()
        pid, fd = pty.fork()
        if pid == 0:
            try:
                os.environ["TERM"] = "xterm-256color"
                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.process_input("\033[01;34mStarted process with PID %d.\033[00m\r\n" % pid)

        self.pid = pid
        self.data_pipe = fd
        self.completed = False

        # 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)

        self.thread = TerminalUpdateThread(self, self.data_pipe, self.exit_pipe)
        self.thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号