tags:

views:

536

answers:

2

Hello, all. 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 any 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!

+2  A: 

Check this question out.

Steve Lazaridis
Excellent. Thank you.I'll post my header file after I'm done so others can find and use it.
Klaus Fiedler
Ok, I didn't use any of the code in it, but it did help me a lot in understanding what I needed to do.
Klaus Fiedler
A: 

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

Intransigent Parsnip
Except some commands ( like 'sudo' ) will terminate automatically unless they're run in some sort of tty. ( Emulated or real. ) Just try using sudo in a script. It won't work. You need to make a pty.
Klaus Fiedler