开发者

Simplest way to get a PTY in Linux C++

开发者 https://www.devze.com 2022-12-18 22:12 出处:网络
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, whic

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

精彩评论

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

关注公众号