KDESu 5.99.0
|
Synchronous communication with tty programs. More...
#include <KDESu/PtyProcess>
Public Types | |
enum | checkPidStatus { Error = -1 , NotExited = -2 , Killed = -3 } |
Error return values for checkPidExited() More... | |
Public Member Functions | |
int | enableLocalEcho (bool enable=true) |
Enables/disables local echo on the pseudo tty. More... | |
int | exec (const QByteArray &command, const QList< QByteArray > &args) |
Forks off and execute a command. More... | |
int | fd () const |
Returns the filedescriptor of the process. More... | |
int | pid () const |
Returns the pid of the process. More... | |
QByteArray | readAll (bool block=true) |
Read all available output from the program's standard out. More... | |
QByteArray | readLine (bool block=true) |
Reads a line from the program's standard out. More... | |
void | setEnvironment (const QList< QByteArray > &env) |
Set additinal environment variables. More... | |
void | setErase (bool erase) |
Overwrites the password as soon as it is used. More... | |
void | setExitString (const QByteArray &exit) |
Sets the exit string. More... | |
void | setTerminal (bool terminal) |
Enables/disables terminal output. More... | |
void | unreadLine (const QByteArray &line, bool addNewline=true) |
Puts back a line of input. More... | |
int | waitForChild () |
Waits for the child to exit. More... | |
int | waitSlave () |
Waits until the pty has cleared the ECHO flag. More... | |
int | WaitSlave () |
void | writeLine (const QByteArray &line, bool addNewline=true) |
Writes a line of text to the program's standard in. More... | |
Static Public Member Functions | |
static bool | checkPid (pid_t pid) |
Basic check for the existence of pid . More... | |
static int | checkPidExited (pid_t pid) |
Check process exit status for process pid . More... | |
static int | waitMS (int fd, int ms) |
Wait ms milliseconds (ie. More... | |
Protected Member Functions | |
PtyProcess (PtyProcessPrivate &dd) | |
QList< QByteArray > | environment () const |
virtual void | virtual_hook (int id, void *data) |
Standard hack to add virtual methods in a BC way. More... | |
Protected Attributes | |
QByteArray | m_command |
Unused. More... | |
bool | m_erase |
QByteArray | m_exitString |
String to scan for in output that indicates child has exited. More... | |
int | m_pid |
PID of child process. More... | |
bool | m_terminal |
Indicates running in a terminal, causes additional newlines to be printed after output. More... | |
Synchronous communication with tty programs.
PtyProcess provides synchronous communication with tty based programs. The communications channel used is a pseudo tty (as opposed to a pipe) This means that programs which require a terminal will work.
Error return values for checkPidExited()
Enumerator | |
---|---|
Error | No child. |
NotExited | Child hasn't exited. |
Killed | Child terminated by signal. |
|
static |
Basic check for the existence of pid
.
Returns true iff pid
is an extant process, (one you could kill - see man kill(2) for signal 0).
|
static |
Check process exit status for process pid
.
If child pid
has exited, return its exit status, (which may be zero). On error (no child, no exit), return -1. If child has
not exited, return -2.
int KDESu::PtyProcess::enableLocalEcho | ( | bool | enable = true | ) |
Enables/disables local echo on the pseudo tty.
int KDESu::PtyProcess::exec | ( | const QByteArray & | command, |
const QList< QByteArray > & | args | ||
) |
Forks off and execute a command.
The command's standard in and output are connected to the pseudo tty. They are accessible with readLine and writeLine.
command | The command to execute. |
args | The arguments to the command. |
int KDESu::PtyProcess::fd | ( | ) | const |
Returns the filedescriptor of the process.
int KDESu::PtyProcess::pid | ( | ) | const |
Returns the pid of the process.
QByteArray KDESu::PtyProcess::readAll | ( | bool | block = true | ) |
Read all available output from the program's standard out.
block | If no output is in the buffer, should the function block (else it will return an empty QByteArray)? |
QByteArray KDESu::PtyProcess::readLine | ( | bool | block = true | ) |
Reads a line from the program's standard out.
Depending on the block parameter, this call blocks until something was read. Note that in some situations this function will return less than a full line of output, but never more. Newline characters are stripped.
block | Block until a full line is read? |
void KDESu::PtyProcess::setEnvironment | ( | const QList< QByteArray > & | env | ) |
Set additinal environment variables.
void KDESu::PtyProcess::setErase | ( | bool | erase | ) |
Overwrites the password as soon as it is used.
Relevant only to some subclasses.
void KDESu::PtyProcess::setExitString | ( | const QByteArray & | exit | ) |
Sets the exit string.
If a line of program output matches this, waitForChild() will terminate the program and return.
void KDESu::PtyProcess::setTerminal | ( | bool | terminal | ) |
Enables/disables terminal output.
Relevant only to some subclasses.
void KDESu::PtyProcess::unreadLine | ( | const QByteArray & | line, |
bool | addNewline = true |
||
) |
Puts back a line of input.
line | The line to put back. |
addNewline | Adds a ' ' to the line. |
|
protectedvirtual |
Standard hack to add virtual methods in a BC way.
Unused.
Reimplemented in KDESu::SshProcess, KDESu::StubProcess, and KDESu::SuProcess.
int KDESu::PtyProcess::waitForChild | ( | ) |
Waits for the child to exit.
See also setExitString.
|
static |
Wait ms
milliseconds (ie.
1/10th of a second is 100ms), using fd
as a filedescriptor to wait on. Returns select(2)'s result, which is -1 on error, 0 on timeout, or positive if there is data on one of the selected fd's.
ms
must be in the range 0..999 (i.e. the maximum wait duration is 999ms, almost one second).
int KDESu::PtyProcess::waitSlave | ( | ) |
Waits until the pty has cleared the ECHO flag.
This is useful when programs write a password prompt before they disable ECHO. Disabling it might flush any input that was written.
|
inline |
void KDESu::PtyProcess::writeLine | ( | const QByteArray & | line, |
bool | addNewline = true |
||
) |
Writes a line of text to the program's standard in.
line | The text to write. |
addNewline | Adds a ' ' to the line. |
|
protected |
Unused.
|
protected |
|
protected |
String to scan for in output that indicates child has exited.
|
protected |
PID of child process.
|
protected |
Indicates running in a terminal, causes additional newlines to be printed after output.
Set to false
in constructor.