當前位置: 首頁>>代碼示例>>Python>>正文


Python os.openpty方法代碼示例

本文整理匯總了Python中os.openpty方法的典型用法代碼示例。如果您正苦於以下問題:Python os.openpty方法的具體用法?Python os.openpty怎麽用?Python os.openpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.openpty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: slave_open

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def slave_open(tty_name):
    """slave_open(tty_name) -> slave_fd
    Open the pty slave and acquire the controlling terminal, returning
    opened filedescriptor.
    Deprecated, use openpty() instead."""

    result = os.open(tty_name, os.O_RDWR)
    try:
        from fcntl import ioctl, I_PUSH
    except ImportError:
        return result
    try:
        ioctl(result, I_PUSH, "ptem")
        ioctl(result, I_PUSH, "ldterm")
    except IOError:
        pass
    return result 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:pty.py

示例2: launch_proc_with_pty

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def launch_proc_with_pty(args, stdin=None, stdout=None, stderr=None, echo=True):
    """Similar to pty.fork, but handle stdin/stdout according to parameters
    instead of connecting to the pty

    :return tuple (subprocess.Popen, pty_master)
    """

    def set_ctty(ctty_fd, master_fd):
        os.setsid()
        os.close(master_fd)
        fcntl.ioctl(ctty_fd, termios.TIOCSCTTY, 0)
        if not echo:
            termios_p = termios.tcgetattr(ctty_fd)
            # termios_p.c_lflags
            termios_p[3] &= ~termios.ECHO
            termios.tcsetattr(ctty_fd, termios.TCSANOW, termios_p)
    (pty_master, pty_slave) = os.openpty()
    # pylint: disable=not-an-iterable
    p = yield from asyncio.create_subprocess_exec(*args,
        stdin=stdin,
        stdout=stdout,
        stderr=stderr,
        preexec_fn=lambda: set_ctty(pty_slave, pty_master))
    os.close(pty_slave)
    return p, open(pty_master, 'wb+', buffering=0) 
開發者ID:QubesOS,項目名稱:qubes-core-admin,代碼行數:27,代碼來源:backup.py

示例3: __call__

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def __call__(self, *objs):
        if self._fo is None:
            masterfd, slavefd = os.openpty()
            pid = os.fork()
            if pid: # parent
                os.close(masterfd)
                self._fo = os.fdopen(slavefd, "w+b", 0)
                if self._do_stderr:
                    os.close(2)
                    os.dup2(slavefd, 2)
            else: # child
                os.close(slavefd)
                os.execlp("urxvt", "urxvt", "-pty-fd", str(masterfd))
        fo = self._fo
        fo.write("{}: ".format(datetime.now()).encode("utf-8"))
        lo = len(objs) - 1
        for i, o in enumerate(objs):
            fo.write(repr(o).encode("utf-8"))
            if i < lo:
                fo.write(b", ")
        fo.write(b"\n")


# automatic, lazy construction of DEBUG object 
開發者ID:kdart,項目名稱:pycopia,代碼行數:26,代碼來源:logwindow.py

示例4: __init__

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def __init__(self):
        masterfd, slavefd = os.openpty()
        pid = os.fork()
        if pid: # parent
            os.close(masterfd)
            self._fo = os.fdopen(slavefd, "w+", 0)
        else: # child
            os.close(slavefd)
            os.execlp("urxvt", "urxvt", "-pty-fd", str(masterfd))
        self.mode = "rw"
        self.closed = 0
        self.softspace = 0
        # reading methods
        self.read = self._fo.read
        self.readline = self._fo.readline
        self.readlines = self._fo.readlines
        # writing methods
        self.write = self._fo.write
        self.flush = self._fo.flush
        self.writelines = self._fo.writelines 
開發者ID:kdart,項目名稱:pycopia,代碼行數:22,代碼來源:IOurxvt.py

示例5: slave_open

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def slave_open(tty_name):
    """slave_open(tty_name) -> slave_fd
    Open the pty slave and acquire the controlling terminal, returning
    opened filedescriptor.
    Deprecated, use openpty() instead."""

    result = os.open(tty_name, os.O_RDWR)
    try:
        from fcntl import ioctl, I_PUSH
    except ImportError:
        return result
    try:
        ioctl(result, I_PUSH, "ptem")
        ioctl(result, I_PUSH, "ldterm")
    except OSError:
        pass
    return result 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:pty.py

示例6: test_baseline_tty_test_code_no_pipe

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_baseline_tty_test_code_no_pipe():
    """Baseline the test code with no pipes on stdin or stdout."""
    master, slave = os.openpty()
    subprocess.run(get_python_command(CODE_ISATTY),
                   check=True,
                   shell=True,
                   stdin=slave,
                   stdout=slave)

    assert 'stdin=True, stdout=True' in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例7: test_baseline_tty_test_code_in_pipe

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_baseline_tty_test_code_in_pipe():
    """Baseline the test code with a pipe on stdin."""
    master, slave = os.openpty()
    subprocess.run(get_python_command(CODE_ISATTY),
                   check=True,
                   shell=True,
                   stdin=subprocess.PIPE,
                   stdout=slave)

    assert 'stdin=False, stdout=True' in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例8: test_baseline_tty_test_code_out_pipe

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_baseline_tty_test_code_out_pipe():
    """Baseline the test code with a pipe on stdout."""
    _, slave = os.openpty()
    result = subprocess.run(get_python_command(CODE_ISATTY),
                            check=True,
                            shell=True,
                            stdin=slave,
                            stdout=subprocess.PIPE)

    assert 'stdin=True, stdout=False' in result.stdout.decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例9: test_baseline_tty_test_code_ttyname_same

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_baseline_tty_test_code_ttyname_same():
    """Baseline the ttyname code, ensuring it detects matching ttys."""
    master, slave = os.openpty()

    subprocess.run(get_python_command(CODE_TTYNAME),
                   check=True,
                   shell=True,
                   stdin=slave,
                   stdout=slave)

    assert os.ttyname(slave) in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:13,代碼來源:test_cli.py

示例10: test_baseline_tty_test_code_ttyname_different

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_baseline_tty_test_code_ttyname_different():
    """Baseline the ttyname code, ensuring it detects different ttys."""
    master, slave = os.openpty()
    _, another_slave = os.openpty()

    subprocess.run(get_python_command(CODE_TTYNAME),
                   check=True,
                   shell=True,
                   stdin=slave,
                   stdout=slave)

    assert os.ttyname(another_slave) not in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:14,代碼來源:test_cli.py

示例11: test_main_run_no_pipe

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_main_run_no_pipe():
    """Have CT run the tty test code with no pipes."""
    master, slave = os.openpty()
    subprocess.run(CLI + ' ' + get_python_command(CODE_ISATTY),
                   check=True,
                   shell=True,
                   stdin=slave,
                   stdout=slave)

    assert 'stdin=True, stdout=True' in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例12: test_main_run_pipe_in

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_main_run_pipe_in():
    """Have CT run the tty test code with a pipe on stdin."""
    master, slave = os.openpty()
    subprocess.run(CLI + ' ' + get_python_command(CODE_ISATTY),
                   check=True,
                   shell=True,
                   stdin=subprocess.PIPE,
                   stdout=slave)

    assert 'stdin=True, stdout=True' in os.read(master, 100).decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例13: test_main_run_pipe_out

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def test_main_run_pipe_out():
    """Have CT run the tty test code with a pipe on stdout."""
    _, slave = os.openpty()
    result = subprocess.run(CLI + ' ' + get_python_command(CODE_ISATTY),
                            check=True,
                            shell=True,
                            stdin=slave,
                            stdout=subprocess.PIPE)

    assert 'stdin=True, stdout=True' in result.stdout.decode() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例14: openpty

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def openpty():
    """openpty() -> (master_fd, slave_fd)
    Open a pty master/slave pair, using os.openpty() if possible."""

    try:
        return os.openpty()
    except (AttributeError, OSError):
        pass
    master_fd, slave_name = _open_terminal()
    slave_fd = slave_open(slave_name)
    return master_fd, slave_fd 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:pty.py

示例15: master_open

# 需要導入模塊: import os [as 別名]
# 或者: from os import openpty [as 別名]
def master_open():
    """master_open() -> (master_fd, slave_name)
    Open a pty master and return the fd, and the filename of the slave end.
    Deprecated, use openpty() instead."""

    try:
        master_fd, slave_fd = os.openpty()
    except (AttributeError, OSError):
        pass
    else:
        slave_name = os.ttyname(slave_fd)
        os.close(slave_fd)
        return master_fd, slave_name

    return _open_terminal() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:pty.py


注:本文中的os.openpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。