pty

Piping data to Linux program which expects a TTY (terminal)

谁说胖子不能爱 提交于 2019-11-27 04:24:19
I have a program in Linux which refuses to run if its stdin/stdout is not a TTY (terminal device). Is there an easy-to-use tool which will create a PTY, start the program with the newly created TTY, and copy all data over stdin/stdout? The use case is not interactive, but scripting. I'm looking for the most lightweight solution, preferably not creating TCP connections, and not requiring too many other tools and libraries to be installed. Ignacio Vazquez-Abrams unbuffer , part of expect ( sudo apt-get install expect-dev on Ubuntu Lucid), can fool a program into thinking it's connected to a TTY.

How can I detect when someone opens the slave side of a pty (pseudo-terminal) in Linux?

倖福魔咒の 提交于 2019-11-27 02:19:30
问题 Having more than one process read from a serial device (/dev/ttyXX) makes it so that both processes can't get all of the data -- the data will be split between them in some way. I'd like to write a program that reads from a serial device, creates several master/slave pty pairs, and then allows programs that were made to read from the serial device to instead read from the ptys so that all reading processes receive the data from the serial device and have the ptys act like the serial device in

How do I read the output of a child process without blocking in Rust?

妖精的绣舞 提交于 2019-11-26 22:46:10
I'm making a small ncurses application in Rust that needs to communicate with a child process. I already have a prototype written in Common Lisp. I'm trying to rewrite it because CL uses a huge amount of memory for such a small tool. I'm having some trouble figuring out how to interact with the sub-process. What I'm currently doing is roughly this: Create the process: let mut program = match Command::new(command) .args(arguments) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() { Ok(child) => child, Err(_) => { println!("Cannot run program '{}'.", command);

How to use pseudo-terminals in Linux with C?

霸气de小男生 提交于 2019-11-26 17:14:43
问题 I'm trying to figure out how to use pseudo-terminal's in linux, essentially I want to create a telnetd clone, something I mentioned in an earlier question. I understand the concept of master and slave terminal, and I have a basic grasp on how to use syscalls in C. My question concerns the next step after opening a slave / master file descriptor. How to I launch getty in the slave? Are there any good resources on the net for using the forkpty(), openpty(),or another API? Some examples in C

Run command and get its stdout, stderr separately in near real time like in a terminal

亡梦爱人 提交于 2019-11-26 11:50:58
I am trying to find a way in Python to run other programs in such a way that: The stdout and stderr of the program being run can be logged separately. The stdout and stderr of the program being run can be viewed in near-real time, such that if the child process hangs, the user can see. (i.e. we do not wait for execution to complete before printing the stdout/stderr to the user) Bonus criteria: The program being run does not know it is being run via python, and thus will not do unexpected things (like chunk its output instead of printing it in real-time, or exit because it demands a terminal to

What is the equivalent of unbuffer program on Windows?

我与影子孤独终老i 提交于 2019-11-26 11:16:34
问题 Hi according to this post, unbuffer connects to a command via a pseudo-terminal (pty), which makes the system treat it as an interactive process, therefore not using any stdout buffering. I would like to use this function on Windows. May I know what is the equivalent of unbuffer program on Windows? Thanks. 回答1: The behaviour you're describing is typical of applications using run-time libraries for I/O. By default, most runtime libraries check to see whether the handle is a character mode

Piping data to Linux program which expects a TTY (terminal)

别来无恙 提交于 2019-11-26 11:09:50
问题 I have a program in Linux which refuses to run if its stdin/stdout is not a TTY (terminal device). Is there an easy-to-use tool which will create a PTY, start the program with the newly created TTY, and copy all data over stdin/stdout? The use case is not interactive, but scripting. I\'m looking for the most lightweight solution, preferably not creating TCP connections, and not requiring too many other tools and libraries to be installed. 回答1: unbuffer , part of expect ( sudo apt-get install

Confused about Docker -t option to Allocate a pseudo-TTY

*爱你&永不变心* 提交于 2019-11-26 08:42:41
问题 What exactly does this option do? I\'ve been reading a lot on TTY and am still confused. I played around with not having the -t and just -i and it seems like programs that expect user input throw an error without the -t . Why is it important for pseudo-TTY to be enabled? 回答1: The -t option goes to how Unix/Linux handles terminal access. In the past, a terminal was a hardline connection, later a modem based connection. These had physical device drivers (they were real pieces of equipment).

How do I read the output of a child process without blocking in Rust?

北战南征 提交于 2019-11-26 08:26:06
问题 I\'m making a small ncurses application in Rust that needs to communicate with a child process. I already have a prototype written in Common Lisp. I\'m trying to rewrite it because CL uses a huge amount of memory for such a small tool. I\'m having some trouble figuring out how to interact with the sub-process. What I\'m currently doing is roughly this: Create the process: let mut program = match Command::new(command) .args(arguments) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr

Last unbuffered line can't be read

ぃ、小莉子 提交于 2019-11-26 04:01:59
问题 I\'m trying to read the last line from a command like \'apt-get download firefox\'. Normally the output will be like Get:1 http://archive.ubuntu.com/ubuntu/ utopic/main firefox amd64 32.0+build1-0ubuntu2 [34.9 MB] 2% [1 firefox 646 kB/34.9 MB 2%] with the last line continuously updating (it is not writing a newline until it reaches 100%). My goal is now to read the progress in realtime. Here is my current example code: #!/usr/bin/python3 -u # coding=utf-8 import subprocess, sys pipe =