Search for usage in LXR

#include <KDESu/PtyProcess>

Inheritance diagram for KDESu::PtyProcess:

Public Types

enum  checkPidStatus { Error = -1, NotExited = -2, Killed = -3 }

Public Member Functions

int enableLocalEcho (bool enable=true)
int exec (const QByteArray &command, const QList< QByteArray > &args)
int fd () const
int pid () const
QByteArray readAll (bool block=true)
QByteArray readLine (bool block=true)
void setEnvironment (const QList< QByteArray > &env)
void setErase (bool erase)
void setExitString (const QByteArray &exit)
void setTerminal (bool terminal)
void unreadLine (const QByteArray &line, bool addNewline=true)
int waitForChild ()
int waitSlave ()
int WaitSlave ()
void writeLine (const QByteArray &line, bool addNewline=true)

Static Public Member Functions

static bool checkPid (pid_t pid)
static int checkPidExited (pid_t pid)
static int waitMS (int fd, int ms)

Protected Member Functions

 PtyProcess (PtyProcessPrivate &dd)
QList< QByteArrayenvironment () const
virtual void virtual_hook (int id, void *data)

Protected Attributes

QByteArray m_command
bool m_erase
QByteArray m_exitString
int m_pid
bool m_terminal

Detailed Description

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.

Definition at line 35 of file ptyprocess.h.

Member Enumeration Documentation

◆ checkPidStatus

Error return values for checkPidExited()


No child.


Child hasn't exited.


Child terminated by signal.

Definition at line 39 of file ptyprocess.h.

Member Function Documentation

◆ checkPid()

bool KDESu::PtyProcess::checkPid ( pid_t  pid)

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).

Definition at line 73 of file ptyprocess.cpp.

◆ checkPidExited()

int KDESu::PtyProcess::checkPidExited ( pid_t  pid)

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.

Definition at line 93 of file ptyprocess.cpp.

◆ enableLocalEcho()

int KDESu::PtyProcess::enableLocalEcho ( bool  enable = true)

Enables/disables local echo on the pseudo tty.

Definition at line 372 of file ptyprocess.cpp.

◆ environment()

QList< QByteArray > KDESu::PtyProcess::environment ( ) const

Returns the additional environment variables set by setEnvironment()

Definition at line 159 of file ptyprocess.cpp.

◆ exec()

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.

commandThe command to execute.
argsThe arguments to the command.
0 on success, -1 on error. errno might give more information then.

Definition at line 265 of file ptyprocess.cpp.

◆ fd()

int KDESu::PtyProcess::fd ( ) const

Returns the filedescriptor of the process.

Definition at line 148 of file ptyprocess.cpp.

◆ pid()

int KDESu::PtyProcess::pid ( ) const

Returns the pid of the process.

Definition at line 153 of file ptyprocess.cpp.

◆ readAll()

QByteArray KDESu::PtyProcess::readAll ( bool  block = true)

Read all available output from the program's standard out.

blockIf no output is in the buffer, should the function block (else it will return an empty QByteArray)?
The output.

Definition at line 164 of file ptyprocess.cpp.

◆ readLine()

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.

blockBlock until a full line is read?
The output string.

Definition at line 215 of file ptyprocess.cpp.

◆ setEnvironment()

void KDESu::PtyProcess::setEnvironment ( const QList< QByteArray > &  env)

Set additinal environment variables.

Set additional environment variables.

Definition at line 143 of file ptyprocess.cpp.

◆ setErase()

void KDESu::PtyProcess::setErase ( bool  erase)

Overwrites the password as soon as it is used.

Relevant only to some subclasses.

Definition at line 382 of file ptyprocess.cpp.

◆ setExitString()

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.

Definition at line 257 of file ptyprocess.cpp.

◆ setTerminal()

void KDESu::PtyProcess::setTerminal ( bool  terminal)

Enables/disables terminal output.

Relevant only to some subclasses.

Definition at line 377 of file ptyprocess.cpp.

◆ unreadLine()

void KDESu::PtyProcess::unreadLine ( const QByteArray line,
bool  addNewline = true 

Puts back a line of input.

lineThe line to put back.
addNewlineAdds a '
' to the line.

Definition at line 246 of file ptyprocess.cpp.

◆ virtual_hook()

void KDESu::PtyProcess::virtual_hook ( int  id,
void *  data 

Standard hack to add virtual methods in a BC way.


Reimplemented in KDESu::StubProcess, KDESu::SuProcess, and KDESu::SshProcess.

Definition at line 514 of file ptyprocess.cpp.

◆ waitForChild()

int KDESu::PtyProcess::waitForChild ( )

Waits for the child to exit.

See also setExitString.

Definition at line 394 of file ptyprocess.cpp.

◆ waitMS()

int KDESu::PtyProcess::waitMS ( int  fd,
int  ms 

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).

Definition at line 54 of file ptyprocess.cpp.

◆ waitSlave()

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.

Definition at line 349 of file ptyprocess.cpp.

◆ WaitSlave()

int KDESu::PtyProcess::WaitSlave ( )
since 5.0, use waitSlave()

Definition at line 113 of file ptyprocess.h.

◆ writeLine()

void KDESu::PtyProcess::writeLine ( const QByteArray line,
bool  addNewline = true 

Writes a line of text to the program's standard in.

lineThe text to write.
addNewlineAdds a '
' to the line.

Definition at line 236 of file ptyprocess.cpp.

Member Data Documentation

◆ m_command

QByteArray KDESu::PtyProcess::m_command


Definition at line 197 of file ptyprocess.h.

◆ m_erase

bool KDESu::PtyProcess::m_erase
See also

Definition at line 192 of file ptyprocess.h.

◆ m_exitString

QByteArray KDESu::PtyProcess::m_exitString

String to scan for in output that indicates child has exited.

Definition at line 198 of file ptyprocess.h.

◆ m_pid

int KDESu::PtyProcess::m_pid

PID of child process.

Definition at line 196 of file ptyprocess.h.

◆ m_terminal

bool KDESu::PtyProcess::m_terminal

Indicates running in a terminal, causes additional newlines to be printed after output.

Set to false in constructor.

See also

Definition at line 193 of file ptyprocess.h.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Jul 1 2022 05:05:16 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.