开发者

Simplest way to get a PTY in Linux C++

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

I found some things like forkpty(), openpty(), etc. in the GNU Standard C libraries, but could not figure out how to use them or find a开发者_开发百科ny good examples, even after reading their corresponding manpages. Literally, all this part of my program needs to do is be able to read/write from a tty running /bin/bash. Is it really that simple, or is there more to it than meets the eye?

If so, can anyone please provide a concise example on how to do this? Thanks in advance! EDIT: Here's the header file I've come up with!


Consider the option of running /bin/sh -s, which means "read commands from standard input". That removes the need to emulate a terminal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜