本文整理汇总了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
示例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)
示例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
示例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
示例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
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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()