当前位置: 首页>>代码示例>>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;未经允许,请勿转载。