The easiest way to get PTY in Linux C ++

I am programming something that requires a Bash interface. At first I thought I could just use popen or QProcess. (I am using QT C ++). They work fine, but I can't get them to run Bash in tty, which is what you need if you intend to use something like sudo, which requires tty / pty to accept the password.

In the GNU Standard C libraries, I found some things, such as forkpty (), openpty (), etc., but could not figure out how to use them or find good examples, even after reading their respective manpages. Literally, all of this part of my program should be able to read / write from tty running / bin / bash. Is it really that simple or is there more than meets the eye?

If so, can you provide a brief example on how to do this? Thank you in advance! EDIT: Here is the header file I came up with!

+3
source share
1 answer

Consider the possibility of starting /bin/sh -s, which means "reading commands from standard input." This eliminates the need for terminal emulation.

-1
source

Source: https://habr.com/ru/post/1730400/


All Articles