Python os.openpty() Method
os.openpty() Overview
The os.openpty() method is used to open a new pseudo-terminal pair. Returns the file descriptors for pty and tty.
os.openpty() Syntax
The syntax format of the openpty() method is as follows.
os.openpty()
os.openpty() Parameters
- None
os.openpty() Return Value
Returns the file descriptor pair, master and slave.
os.openpty() Demo
The following example demonstrates the use of the openpty() method.
#!/usr/bin/python3
import os
# Master pty, slave tty
m,s = os.openpty()
print (m)
print (s)
# Display terminal name
s = os.ttyname(s)
print (m)
print (s)
Output:
program to explain os.openpty() method
import os
# open new pseudo-terminal pair using os.openpty() method
master, slave = os.openpty()
# Get the terminal device name associated with file descriptor master
name = os.ttyname(master)
print(name)
# Get the terminal device name associated with file descriptor slave
name = os.ttyname(slave)
print(name)
Output:
/dev/ptmx
/dev/pts/7