pty

changing pseudo tty echo mode from the master side

拜拜、爱过 提交于 2020-07-16 04:39:10
问题 On linux, I am opening a pseudo tty on the master side. While there is no client on the slave side, the pseudo tty seems to be echoing everything I am writing to him, which is not what I am expecting. Consider the folowing code : int main(int argc, char * argv[]) { int ptyfd; int rc; /* return code */ char readbuf[3]; ptyfd = open("/dev/ptmx", O_RDWR | O_NOCTTY); die_on_error(ptyfd, "open ptmx"); /* unlock and print slave name */ rc = unlockpt(ptyfd); die_on_error(rc, "unlockpt"); printf(

How to capture inputs and outputs of a child process?

让人想犯罪 __ 提交于 2020-07-08 04:58:40
问题 I'm trying to make a program which takes an executable name as an argument, runs the executable and reports the inputs and outputs for that run. For example consider a child program named "circle". The following would be desired run for my program: $ python3 capture_io.py ./circle Enter radius of circle: 10 Area: 314.158997 [('output', 'Enter radius of circle: '), ('input', '10\n'), ('output', 'Area: 314.158997\n')] I decided to use pexpect module for this job. It has a method called interact

difference between pty and a pipe

左心房为你撑大大i 提交于 2020-05-25 04:19:50
问题 I have been reading about ptys from this page's example: http://rachid.koucha.free.fr/tech_corner/pty_pdip.html. I have two questions: What is the difference, or the most important difference, between using a pty and using a pipe? From what I have read, both are for inter-process communication, but with a pty the process can "treat it like a normal terminal". What does that mean? What is a "controlling terminal"? I have read about them but can't understand what they really are. Is the

difference between pty and a pipe

﹥>﹥吖頭↗ 提交于 2020-05-25 04:19:26
问题 I have been reading about ptys from this page's example: http://rachid.koucha.free.fr/tech_corner/pty_pdip.html. I have two questions: What is the difference, or the most important difference, between using a pty and using a pipe? From what I have read, both are for inter-process communication, but with a pty the process can "treat it like a normal terminal". What does that mean? What is a "controlling terminal"? I have read about them but can't understand what they really are. Is the

Using the linux pseudo terminal API for multiple debug terminals

人盡茶涼 提交于 2020-01-17 03:34:13
问题 Ubuntu Linux: How can one acquire a path that refers to the master side of a of a pseudo terminal pair?... the slave side is easy... but the master side only seems to exist as an open file descriptor, but seems not possess a valid Linux path. With respect to the working Linux pseudo terminal example http://www.man7.org/tlpi/code/online/all_files_by_chapter.html#ch64 covered in the last chapter of this very good Liunx API book: http://www.nostarch.com/tlpi A questions regarding the current

Golang write input and get output from terminal process

只愿长相守 提交于 2020-01-11 04:06:06
问题 I have a question regarding how to send input and receive output from a terminal subprocess such as ssh. An example in python would be something like this: how to give subprocess a password and get stdout at the same time I cannot find a simple example in Golang that is similar how the above work. In Golang I would want to do something like this but it does not seem to work: cmd := exec.Command("ssh", "user@x.x.x.x") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr stdin, _ := cmd.StdinPipe()

Golang reading from stdin, how to detect special keys (enter, backspace… etc)

帅比萌擦擦* 提交于 2020-01-10 20:07:10
问题 I have the following program that reads user input from stdin: var input string = "" exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() exec.Command("stty", "-F", "/dev/tty", "-echo").Run() var b []byte = make([]byte, 1) for { input += string(b) } I want to place some kind of condition inside the for loop so that i can "break" when the user presses "enter" (for example) or remove one char from a string when the user presses (backspace). However, i can't figure out what the

Python: How to peek into a pty object to avoid blocking?

爷,独闯天下 提交于 2020-01-10 15:33:01
问题 I am using pty to read non blocking the stdout of a process like this: import os import pty import subprocess master, slave = pty.openpty() p = subprocess.Popen(cmd, stdout = slave) stdout = os.fdopen(master) while True: if p.poll() != None: break print stdout.readline() stdout.close() Everything works fine except that the while-loop occasionally blocks. This is due to the fact that the line print stdout.readline() is waiting for something to be read from stdout . But if the program already

Python: How to peek into a pty object to avoid blocking?

我只是一个虾纸丫 提交于 2020-01-10 15:32:25
问题 I am using pty to read non blocking the stdout of a process like this: import os import pty import subprocess master, slave = pty.openpty() p = subprocess.Popen(cmd, stdout = slave) stdout = os.fdopen(master) while True: if p.poll() != None: break print stdout.readline() stdout.close() Everything works fine except that the while-loop occasionally blocks. This is due to the fact that the line print stdout.readline() is waiting for something to be read from stdout . But if the program already