KPty 5.109.0
Public Types | Public Member Functions | List of all members
KPtyProcess

This class extends KProcess by support for PTYs (pseudo TTYs). More...

#include <kptyprocess.h>

Public Types

enum  PtyChannelFlag {
  NoChannels = 0 , StdinChannel = 1 , StdoutChannel = 2 , StderrChannel = 4 ,
  AllOutputChannels = 6 , AllChannels = 7
}
 
typedef QFlags< PtyChannelFlagPtyChannels
 Stores a combination of #PtyChannelFlag values.
 

Public Member Functions

 KPtyProcess (int ptyMasterFd, QObject *parent=nullptr)
 Construct a process using an open pty master.
 
 KPtyProcess (QObject *parent=nullptr)
 Constructor.
 
 ~KPtyProcess () override
 Destructor.
 
bool isUseUtmp () const
 Get whether to register the process as a TTY login in utmp.
 
KPtyDevicepty () const
 Get the PTY device of this process.
 
PtyChannels ptyChannels () const
 Query to which channels the PTY is assigned.
 
void setPtyChannels (PtyChannels channels)
 Set to which channels the PTY should be assigned.
 
void setUseUtmp (bool value)
 Set whether to register the process as a TTY login in utmp.
 

Detailed Description

This class extends KProcess by support for PTYs (pseudo TTYs).

The PTY is opened as soon as the class is instantiated. Verify that it was opened successfully by checking that pty()->masterFd() is not -1.

The PTY is always made the process' controlling TTY. Utmp registration and connecting the stdio handles to the PTY are optional.

No attempt to integrate with QProcess' waitFor*() functions was made, for it is impossible. Note that execute() does not work with the PTY, too. Use the PTY device's waitFor*() functions or use it asynchronously.

Note
If you inherit from this class and use setChildProcessModifier() in the derived class, you must call the childProcessModifier() of KPtyProcess first (using setChildProcessModifier() in the derived class will "overwrite" the childProcessModifier() std::function that was previously set by KPtyProcess). For example:
class MyProcess : public KPtyProcess
{
MyProcess()
{
auto parentChildProcModifier = KPtyProcess::childProcessModifier();
setChildProcessModifier([parentChildProcModifier]() {
// First call the parent class modifier function
if (parentChildProcModifier) {
parentChildProcModifier();
}
// Then whatever extra code you need to run
....
....
});
}
This class extends KProcess by support for PTYs (pseudo TTYs).
Definition kptyprocess.h:60
Author
Oswald Buddenhagen ossi@.nosp@m.kde..nosp@m.org

Member Typedef Documentation

◆ PtyChannels

Stores a combination of #PtyChannelFlag values.

Member Enumeration Documentation

◆ PtyChannelFlag

See also
PtyChannels
Enumerator
NoChannels 

The PTY is not connected to any channel.

StdinChannel 

Connect PTY to stdin.

StdoutChannel 

Connect PTY to stdout.

StderrChannel 

Connect PTY to stderr.

AllOutputChannels 

Connect PTY to all output channels.

AllChannels 

Connect PTY to all channels.

Constructor & Destructor Documentation

◆ KPtyProcess() [1/2]

KPtyProcess::KPtyProcess ( QObject *  parent = nullptr)
explicit

Constructor.

◆ KPtyProcess() [2/2]

KPtyProcess::KPtyProcess ( int  ptyMasterFd,
QObject *  parent = nullptr 
)

Construct a process using an open pty master.

Parameters
ptyMasterFdan open pty master file descriptor. The process does not take ownership of the descriptor; it will not be automatically closed at any point.

◆ ~KPtyProcess()

KPtyProcess::~KPtyProcess ( )
override

Destructor.

Member Function Documentation

◆ isUseUtmp()

bool KPtyProcess::isUseUtmp ( ) const

Get whether to register the process as a TTY login in utmp.

Returns
whether to register in utmp

◆ pty()

KPtyDevice * KPtyProcess::pty ( ) const

Get the PTY device of this process.

Returns
the PTY device

◆ ptyChannels()

PtyChannels KPtyProcess::ptyChannels ( ) const

Query to which channels the PTY is assigned.

Returns
the output channel handling mode

◆ setPtyChannels()

void KPtyProcess::setPtyChannels ( PtyChannels  channels)

Set to which channels the PTY should be assigned.

This function must be called before starting the process.

Parameters
channelsthe output channel handling mode

◆ setUseUtmp()

void KPtyProcess::setUseUtmp ( bool  value)

Set whether to register the process as a TTY login in utmp.

Utmp is disabled by default. It should enabled for interactively fed processes, like terminal emulations.

This function must be called before starting the process.

Parameters
valuewhether to register in utmp.