kdecore Library API Documentation

KProcIO Class Reference

KProcIO A slightly simpler interface to KProcess. More...

#include <kprocio.h>

Inheritance diagram for KProcIO:

KProcess QObject List of all members.

Signals

void readReady (KProcIO *pio)
 Emitted when the process is ready for reading.


Public Methods

bool start (RunMode runmode=NotifyOnExit, bool includeStderr=false)
 Starts the process.

bool writeStdin (const QString &line, bool appendnewline=TRUE)
 Writes text to stdin of the process.

bool writeStdin (const QCString &line, bool appendnewline)
 Writes text to stdin of the process.

bool writeStdin (const QByteArray &data)
 Writes data to stdin of the process.

bool fputs (const QString &line, bool AppendNewLine=TRUE)
 This function just calls writeStdin().

void closeWhenDone ()
 closes stdin after all data has been send.

int readln (QString &line, bool autoAck=true, bool *partial=0)
 Reads a line of text (up to and including '
').


int fgets (QString &line, bool autoAck=false)
 This function calls readln().

void resetAll ()
 Reset the class.

void ackRead ()
 Call this after you have finished processing a readReady() signal.

void enableReadSignals (bool enable)
 Turns readReady() signals on and off.


Protected Methods

virtual void virtual_hook (int id, void *data)

Detailed Description

KProcIO A slightly simpler interface to KProcess.

This class provides a slightly simpler interface to the communication functions provided by KProcess. The simplifications are:

Basically, KProcIO gives you buffered I/O similar to fgets()/fputs().

Aside from these, and the fact that start() takes different parameters, use this class just like KProcess.

Version:
Id:
kprocio.h,v 1.15 2002/09/10 19:17:01 tjansen Exp
Author:
David Sweet

Definition at line 50 of file kprocio.h.


Member Function Documentation

bool KProcIO::start RunMode    runmode = NotifyOnExit,
bool    includeStderr = false
 

Starts the process.

It will fail in the following cases:

  • The process is already running.
  • The command line argument list is empty.
  • The starting of the process failed (could not fork).
  • The executable was not found.
Parameters:
runmode  For a detailed description of the various run modes, have a look at the general description of the KProcess class.
includeStderr  If true, data from both stdout and stderr is listened to. If false, only stdout is listened to.
Returns:
true on success, false on error.

Definition at line 76 of file kprocio.cpp.

References QObject::connect(), KProcess::receivedStderr(), KProcess::receivedStdout(), KProcess::start(), and KProcess::wroteStdin().

bool KProcIO::writeStdin const QString   line,
bool    appendnewline = TRUE
 

Writes text to stdin of the process.

Parameters:
line  Text to write.
appendnewline  if true, a newline '
' is appended.
Returns:
true if successful, false otherwise

Definition at line 93 of file kprocio.cpp.

References QTextCodec::fromUnicode().

Referenced by fputs().

bool KProcIO::writeStdin const QCString   line,
bool    appendnewline
 

Writes text to stdin of the process.

Parameters:
line  Text to write.
appendnewline  if true, a newline '
' is appended.
Returns:
true if successful, false otherwise

Definition at line 98 of file kprocio.cpp.

References QPtrList< QByteArray >::append(), QCString::length(), and KProcess::writeStdin().

bool KProcIO::writeStdin const QByteArray   data
 

Writes data to stdin of the process.

Parameters:
data  Data to write.
Returns:
true if successful, false otherwise

Definition at line 127 of file kprocio.cpp.

References QPtrList< QByteArray >::append(), and KProcess::writeStdin().

bool KProcIO::fputs const QString   line,
bool    AppendNewLine = TRUE
[inline]
 

This function just calls writeStdin().

Parameters:
line  Text to write.
AppendNewLine  if true, a newline '
' is appended.
Returns:
true if successful, false otherwise
Deprecated:

Definition at line 107 of file kprocio.h.

References writeStdin().

void KProcIO::closeWhenDone  
 

closes stdin after all data has been send.

Definition at line 142 of file kprocio.cpp.

References QPtrList< QByteArray >::append(), and KProcess::closeStdin().

int KProcIO::readln QString   line,
bool    autoAck = true,
bool *    partial = 0
 

Reads a line of text (up to and including '
').

Use readln() in response to a readReady() signal. You may use it multiple times if more than one line of data is available. Be sure to use ackRead() when you have finished processing the readReady() signal. This informs KProcIO that you are ready for another readReady() signal.

readln() never blocks.

autoAck==TRUE makes these functions call ackRead() for you.

Parameters:
line  is used to store the line that was read.
autoAck  when true, ackRead() is called for you.
partial  when provided the line is returned even if it does not contain a '
'. *partial will be set to false if the line contains a '
' and false otherwise.
Returns:
the number of characters read, or -1 if no data is available.

Definition at line 216 of file kprocio.cpp.

References QCString::find(), QCString::length(), QCString::mid(), and QTextCodec::toUnicode().

Referenced by fgets().

int KProcIO::fgets QString   line,
bool    autoAck = false
[inline]
 

This function calls readln().

Parameters:
line  is used to store the line that was read.
autoAck  when true, ackRead() is called for you.
partial  when provided the line is returned even if it does not contain a '
'. *partial will be set to false if the line contains a '
' and false otherwise.
Returns:
the number of characters read, or -1 if no data is available.
Deprecated:

Definition at line 148 of file kprocio.h.

References readln().

void KProcIO::resetAll  
 

Reset the class.

Doesn't kill the process.

Definition at line 54 of file kprocio.cpp.

References QPtrList< QByteArray >::clear(), KProcess::clearArguments(), QObject::disconnect(), KProcess::isRunning(), KProcess::kill(), KProcess::receivedStderr(), KProcess::receivedStdout(), and KProcess::wroteStdin().

void KProcIO::ackRead  
 

Call this after you have finished processing a readReady() signal.

This call need not be made in the slot that was signalled by readReady(). You won't receive any more readReady() signals until you acknowledge with ackRead(). This prevents your slot from being reentered while you are still processing the current data. If this doesn't matter, then call ackRead() right away in your readReady()-processing slot.

Definition at line 187 of file kprocio.cpp.

References QCString::length().

void KProcIO::enableReadSignals bool    enable
 

Turns readReady() signals on and off.

You can turn this off at will and not worry about losing any data. (as long as you turn it back on at some point...)

Parameters:
enable  true to turn the signals on, false to turn them off

Definition at line 208 of file kprocio.cpp.

References readReady().

void KProcIO::readReady KProcIO *    pio [signal]
 

Emitted when the process is ready for reading.

Parameters:
pio  the process that emitted the signal
See also:
enableReadSignals()

Referenced by enableReadSignals().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:46 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001