Qyoto
4.0.5
Qyoto is a C# language binding for Qt
|
The QProcess class is used to start external programs and to communicate with them. More...
Public Types | |
enum | ExitStatus { CrashExit = 1, NormalExit = 0 } |
More... | |
enum | ProcessChannel { StandardError = 1, StandardOutput = 0 } |
More... | |
enum | ProcessChannelMode { ForwardedChannels = 2, MergedChannels = 1, SeparateChannels = 0 } |
More... | |
enum | ProcessError { Crashed = 1, FailedToStart = 0, ReadError = 3, Timedout = 2, UnknownError = 5, WriteError = 4 } |
More... | |
enum | ProcessState { NotRunning = 0, Running = 2, Starting = 1 } |
More... | |
Public Types inherited from QtCore.QIODevice | |
enum | OpenModeFlag { Append = 4, NotOpen = 0, ReadOnly = 1, ReadWrite = 3, Text = 16, Truncate = 8, Unbuffered = 32, WriteOnly = 2 } |
More... | |
Public Member Functions | |
QProcess (QObject parent=null) | |
| |
override void | CreateProxy () |
override bool | AtEnd () |
| |
override long | BytesAvailable () |
| |
override long | BytesToWrite () |
| |
override bool | CanReadLine () |
| |
override void | Close () |
| |
new void | CloseReadChannel (QProcess.ProcessChannel channel) |
| |
new void | CloseWriteChannel () |
| |
new QProcess.ProcessError | OnError () |
| |
new int | ExitCode () |
| |
new QProcess.ExitStatus | exitStatus () |
| |
override bool | IsSequential () |
| |
new void | Kill () |
| |
new QByteArray | ReadAllStandardError () |
| |
new QByteArray | ReadAllStandardOutput () |
| |
new void | SetStandardErrorFile (string fileName, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.Truncate) |
| |
new void | SetStandardInputFile (string fileName) |
| |
new void | SetStandardOutputFile (string fileName, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.Truncate) |
| |
new void | SetStandardOutputProcess (QProcess destination) |
| |
new void | Start (string program, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.ReadWrite) |
| |
new void | Start (string program, System.Collections.Generic.List< string > arguments, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.ReadWrite) |
| |
new QProcess.ProcessState | State () |
| |
new void | Terminate () |
| |
override bool | WaitForBytesWritten (int msecs=30000) |
| |
new bool | WaitForFinished (int msecs=30000) |
| |
override bool | WaitForReadyRead (int msecs=30000) |
| |
new bool | WaitForStarted (int msecs=30000) |
| |
new void | Dispose () |
Public Member Functions inherited from QtCore.QIODevice | |
QIODevice () | |
| |
QIODevice (QObject parent) | |
| |
new string | ErrorString () |
| |
new bool | GetChar (Pointer< sbyte > c) |
| |
new bool | IsOpen () |
| |
new bool | IsReadable () |
| |
new bool | IsTextModeEnabled () |
| |
new bool | IsWritable () |
| |
virtual bool | Open (QIODevice.OpenModeFlag mode) |
| |
new QIODevice.OpenModeFlag | OpenMode () |
| |
new QByteArray | Peek (long maxlen) |
| |
new long | Peek (Pointer< sbyte > data, long maxlen) |
| |
virtual long | Pos () |
| |
new bool | PutChar (sbyte c) |
| |
new QByteArray | Read (long maxlen) |
| |
new long | Read (Pointer< sbyte > data, long maxlen) |
| |
new QByteArray | ReadAll () |
| |
new QByteArray | ReadLine (long maxlen=0) |
| |
new long | ReadLine (Pointer< sbyte > data, long maxlen) |
| |
virtual bool | Reset () |
| |
virtual bool | Seek (long pos) |
| |
new void | SetTextModeEnabled (bool enabled) |
| |
virtual long | Size () |
| |
new void | UngetChar (sbyte c) |
| |
new long | Write (QByteArray data) |
| |
new long | Write (string data) |
| |
new long | Write (string data, long len) |
| |
new void | Dispose () |
Public Member Functions inherited from QtCore.QObject | |
QObject (QObject parent=null) | |
| |
new bool | BlockSignals (bool b) |
| |
new System.Collections.Generic.List < QObject > | Children () |
| |
new bool | Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
new void | DeleteLater () |
| |
new bool | Disconnect (QObject receiver, string member=null) |
| |
new bool | Disconnect (string signal=null, QObject receiver=null, string member=null) |
| |
new void | DumpObjectInfo () |
| |
new void | DumpObjectTree () |
| |
new System.Collections.Generic.List < QByteArray > | DynamicPropertyNames () |
| |
virtual bool | OnEvent (QEvent arg1) |
| |
virtual bool | EventFilter (QObject arg1, QEvent arg2) |
| |
new bool | Inherits (string classname) |
| |
new void | InstallEventFilter (QObject arg1) |
| |
new bool | IsWidgetType () |
| |
new void | KillTimer (int id) |
| |
new object | Property (string name) |
| |
new void | RemoveEventFilter (QObject arg1) |
| |
new bool | SetProperty (string name, object value) |
| |
new void | SetUserData (uint id, QObjectUserData data) |
new bool | SignalsBlocked () |
| |
new int | StartTimer (int interval) |
| |
new QObjectUserData | UserData (uint id) |
new void | Dispose () |
Public Member Functions inherited from QtCore.Qt | |
delegate QTextStream | FuncQTextStreamQTextStream (QTextStream qTextStream) |
delegate string | FuncStringQByteArray (QByteArray qByteArray) |
delegate QByteArray | FuncQByteArrayString (string @string) |
delegate void | ActionQtMsgTypeString (QtMsgType qtMsgType, string @string) |
delegate QObject | FuncQObject () |
Static Public Member Functions | |
static int | Execute (string program) |
| |
static int | Execute (string program, System.Collections.Generic.List< string > arguments) |
| |
static bool | StartDetached (string program) |
| |
static bool | StartDetached (string program, System.Collections.Generic.List< string > arguments) |
| |
static bool | StartDetached (string program, System.Collections.Generic.List< string > arguments, string workingDirectory) |
| |
static bool | StartDetached (string program, System.Collections.Generic.List< string > arguments, string workingDirectory, ref long pid) |
| |
static System.Collections.Generic.List < string > | SystemEnvironment () |
| |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtCore.QIODevice | |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtCore.QObject | |
static bool | Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
static bool | Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection) |
| |
static bool | Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member) |
| |
static bool | Disconnect (QObject sender, string signal, QObject receiver, string member) |
| |
static uint | RegisterUserData () |
static string | Tr (string s, string c=null) |
| |
static string | Tr (string s, string c, int n) |
| |
static string | TrUtf8 (string s, string c=null) |
| |
static string | TrUtf8 (string s, string c, int n) |
| |
Static Public Member Functions inherited from QtCore.Qt | |
static QDataStream | Write (QDataStream s, object p) |
static QDataStream | Write (QDataStream arg1, QSizeF arg2) |
static QTextStream | Write (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Write (QDataStream arg1, QPoint arg2) |
static QDataStream | Write (QDataStream arg1, QLineF arg2) |
static QDataStream | Write (QDataStream arg1, QPointF arg2) |
static QDataStream | Write (QDataStream arg1, QChar arg2) |
static QDataStream | Write (QDataStream arg1, QByteArray arg2) |
static QDataStream | Write (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Write (QDataStream arg1, QRectF arg2) |
static QDataStream | Write (QDataStream arg1, QDateTime arg2) |
static QDataStream | Write (QDataStream arg1, QUrl arg2) |
static QDataStream | Write (QDataStream arg1, QTime arg2) |
static QDataStream | Write (QDataStream arg1, QLocale arg2) |
static QDataStream | Write (QDataStream arg1, QBitArray arg2) |
static QDataStream | Write (QDataStream arg1, QUuid arg2) |
static QDataStream | Write (QDataStream arg1, QLine arg2) |
static QDataStream | Write (QDataStream arg1, QDate arg2) |
static QDataStream | Write (QDataStream @out, QRegExp regExp) |
static QDataStream | Write (QDataStream arg1, QRect arg2) |
static QDataStream | Write (QDataStream arg1, QSize arg2) |
static QDataStream | Write (QDataStream s, QVariant.Type p) |
static QDataStream | Write (QDataStream arg1, string arg2) |
static QDataStream | Write (QDataStream @out, System.Collections.Generic.List< string > list) |
static QDataStream | Read (QDataStream arg1, QChar arg2) |
static QDataStream | Read (QDataStream arg1, QLocale arg2) |
static QDataStream | Read (QDataStream arg1, QRect arg2) |
static QDataStream | Read (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Read (QDataStream arg1, QDate arg2) |
static QDataStream | Read (QDataStream arg1, QUrl arg2) |
static QDataStream | Read (QDataStream arg1, QUuid arg2) |
static QTextStream | Read (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Read (QDataStream arg1, QLineF arg2) |
static QDataStream | Read (QDataStream arg1, QRectF arg2) |
static QDataStream | Read (QDataStream arg1, QPointF arg2) |
static QDataStream | Read (QDataStream arg1, QLine arg2) |
static QDataStream | Read (QDataStream arg1, QBitArray arg2) |
static QDataStream | Read (QDataStream arg1, QSize arg2) |
static QDataStream | Read (QDataStream arg1, QDateTime arg2) |
static QDataStream | Read (QDataStream arg1, QTime arg2) |
static QDataStream | Read (QDataStream arg1, QPoint arg2) |
static QDataStream | Read (QDataStream @in, QRegExp regExp) |
static QDataStream | Read (QDataStream s, object p) |
static QDataStream | Read (QDataStream arg1, QByteArray arg2) |
static QDataStream | Read (QDataStream arg1, QSizeF arg2) |
static QDataStream | Read (QDataStream arg1, string arg2) |
static QDataStream | Read (QDataStream s, QVariant.Type p) |
static QDataStream | Read (QDataStream @in, System.Collections.Generic.List< string > list) |
static double | qAcos (double v) |
static void | qAddPostRoutine (System.Action arg1) |
static string | qAppName () |
static double | qAsin (double v) |
static double | qAtan (double v) |
static double | qAtan2 (double x, double y) |
static void | qBadAlloc () |
static int | qCeil (double v) |
static ushort | qChecksum (string s, uint len) |
static QByteArray | qCompress (QByteArray data) |
static QByteArray | qCompress (QByteArray data, int compressionLevel=-1) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1) |
static double | qCos (double v) |
static double | qExp (double v) |
static double | qFabs (double v) |
static double | qFastCos (double x) |
static double | qFastSin (double x) |
static string | qFlagLocation (string method) |
static int | qFloor (double v) |
static bool | qFuzzyCompare (double p1, double p2) |
static bool | qFuzzyCompare (float p1, float p2) |
static bool | qFuzzyIsNull (double d) |
static bool | qFuzzyIsNull (float f) |
static uint | qHash (QBitArray key) |
static uint | qHash (QChar key) |
static uint | qHash (QStringRef key) |
static uint | qHash (QUrl url) |
static uint | qHash (QPersistentModelIndex index) |
static uint | qHash (QByteArray key) |
static uint | qHash (QModelIndex index) |
static uint | qHash (uint key) |
static uint | qHash (sbyte key) |
static uint | qHash (byte key) |
static uint | qHash (short key) |
static uint | qHash (NativeLong key) |
static uint | qHash (ushort key) |
static uint | qHash (long key) |
static uint | qHash (ulong key) |
static uint | qHash (int key) |
static uint | qHash (string key) |
static uint | qHash (NativeULong key) |
static double | qInf () |
static Qt.ActionQtMsgTypeString | qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1) |
static int | qIntCast (float f) |
static int | qIntCast (double f) |
static bool | qIsFinite (double d) |
static bool | qIsFinite (float f) |
static bool | qIsInf (float f) |
static bool | qIsInf (double d) |
static bool | qIsNaN (float f) |
static bool | qIsNaN (double d) |
static bool | qIsNull (float f) |
static bool | qIsNull (double d) |
static double | qLn (double v) |
static double | qPow (double x, double y) |
static double | qQNaN () |
static void | qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function) |
static void | qRemovePostRoutine (System.Action arg1) |
static int | qRound (double d) |
static long | qRound64 (double d) |
static double | qSNaN () |
static bool | qSharedBuild () |
static double | qSin (double v) |
static double | qSqrt (double v) |
static bool | qStringComparisonHelper (QStringRef s1, string s2) |
static double | qTan (double v) |
static QByteArray | qUncompress (QByteArray data) |
static QByteArray | qUncompress (Pointer< byte > data, int nbytes) |
static string | qVersion () |
static void | Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size) |
static QByteArray | Qgetenv (string varName) |
static bool | Qputenv (string varName, QByteArray value) |
static int | Qrand () |
static void | Qsrand (uint seed) |
static int | Qstrcmp (QByteArray str1, QByteArray str2) |
static int | Qstrcmp (QByteArray str1, string str2) |
static int | Qstrcmp (string str1, QByteArray str2) |
static int | Qstrcmp (string str1, string str2) |
static Pointer< sbyte > | Qstrcpy (Pointer< sbyte > dst, string src) |
static Pointer< sbyte > | Qstrdup (string arg1) |
static int | Qstricmp (string arg1, string arg2) |
static uint | Qstrlen (string str) |
static int | Qstrncmp (string str1, string str2, uint len) |
static Pointer< sbyte > | Qstrncpy (Pointer< sbyte > dst, string src, uint len) |
static int | Qstrnicmp (string arg1, string arg2, uint len) |
static uint | Qstrnlen (string str, uint maxlen) |
static string | QtTrId (string id, int n=-1) |
Protected Member Functions | |
QProcess (System.Type dummy) | |
new void | OnError (QProcess.ProcessError error) |
| |
new void | OnFinished (int exitCode) |
| |
new void | OnFinished (int exitCode, QProcess.ExitStatus exitStatus) |
| |
override long | ReadData (Pointer< sbyte > data, long maxlen) |
| |
new void | OnReadyReadStandardError () |
| |
new void | OnReadyReadStandardOutput () |
| |
new void | SetProcessState (QProcess.ProcessState state) |
| |
virtual void | SetupChildProcess () |
| |
new void | OnStarted () |
| |
new void | OnStateChanged (QProcess.ProcessState state) |
| |
override long | WriteData (string data, long len) |
| |
Protected Member Functions inherited from QtCore.QIODevice | |
QIODevice (System.Type dummy) | |
new void | OnAboutToClose () |
| |
new void | OnBytesWritten (long bytes) |
| |
new void | OnReadChannelFinished () |
| |
virtual long | ReadLineData (Pointer< sbyte > data, long maxlen) |
| |
new void | OnReadyRead () |
| |
new void | SetErrorString (string errorString) |
| |
new void | SetOpenMode (QIODevice.OpenModeFlag openMode) |
| |
Protected Member Functions inherited from QtCore.QObject | |
QObject (System.Type dummy) | |
virtual void | OnChildEvent (QChildEvent arg1) |
| |
virtual void | ConnectNotify (string signal) |
| |
virtual void | OnCustomEvent (QEvent arg1) |
| |
new void | OnDestroyed (QObject arg1=null) |
| |
virtual void | DisconnectNotify (string signal) |
| |
new int | Receivers (string signal) |
| |
new QObject | Sender () |
| |
new int | SenderSignalIndex () |
| |
virtual void | OnTimerEvent (QTimerEvent arg1) |
| |
Additional Inherited Members | |
Protected Attributes inherited from QtCore.QObject | |
object | Q_EMIT = null |
SmokeInvocation | interceptor |
readonly List< QEventHandler > | eventFilters = new List<QEventHandler>() |
The QProcess class is used to start external programs and to communicate with them.
Running a Process
To start a process, pass the name and command line arguments of the program you want to run as arguments to start(). Arguments are supplied as individual strings in a QStringList.
For example, the following code snippet runs the analog clock example in the Motif style on X11 platforms by passing strings containing "-style" and "motif" as two items in the list of arguments:
QObject *parent;
...
QString program = "./path/to/Qt/examples/widgets/analogclock";
QStringList arguments;
arguments << "-style" << "motif";
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);
QProcess then enters the Starting state, and when the program has started, QProcess enters the Running state and emits started().
QProcess allows you to treat a process as a sequential I/O device. You can write to and read from the process just as you would access a network connection using QTcpSocket. You can then write to the process's standard input by calling write(), and read the standard output by calling read(), readLine(), and getChar(). Because it inherits QIODevice, QProcess can also be used as an input source for QXmlReader, or for generating data to be uploaded using QFtp.
Note: On Windows CE and Symbian, reading and writing to a process is not supported.
When the process exits, QProcess reenters the NotRunning state (the initial state), and emits finished().
The finished() signal provides the exit code and exit status of the process as arguments, and you can also call exitCode() to obtain the exit code of the last process that finished, and exitStatus() to obtain its exit status. If an error occurs at any point in time, QProcess will emit the error() signal. You can also call error() to find the type of error that occurred last, and state() to find the current process state.
Communicating via Channels
Processes have two predefined output channels: The standard output channel (stdout) supplies regular console output, and the standard error channel (stderr) usually supplies the errors that are printed by the process. These channels represent two separate streams of data. You can toggle between them by calling setReadChannel(). QProcess emits readyRead() when data is available on the current read channel. It also emits readyReadStandardOutput() when new standard output data is available, and when new standard error data is available, readyReadStandardError() is emitted. Instead of calling read(), readLine(), or getChar(), you can explicitly read all data from either of the two channels by calling readAllStandardOutput() or readAllStandardError().
The terminology for the channels can be misleading. Be aware that the process's output channels correspond to QProcess's read channels, whereas the process's input channels correspond to QProcess's write channels. This is because what we read using QProcess is the process's output, and what we write becomes the process's input.
QProcess can merge the two output channels, so that standard output and standard error data from the running process both use the standard output channel. Call setProcessChannelMode() with MergedChannels before starting the process to activative this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing ForwardedChannels as the argument.
Certain processes need special environment settings in order to operate. You can set environment variables for your process by calling setEnvironment(). To set a working directory, call setWorkingDirectory(). By default, processes are run in the current working directory of the calling process.
Note: On Symbian, setting environment or working directory is not supported. The working directory will always be the private directory of the running process.
Note: On QNX, setting the working directory may cause all application threads, with the exception of the QProcess caller thread, to temporarily freeze, owing to a limitation in the operating system.
Synchronous Process API
QProcess provides a set of functions which allow it to be used without an event loop, by suspending the calling thread until certain signals are emitted:
waitForStarted() blocks until the process has started.
waitForReadyRead() blocks until new data is available for reading on the current read channel.
waitForBytesWritten() blocks until one payload of data has been written to the process.
waitForFinished() blocks until the process has finished.
Calling these functions from the main thread (the thread that calls QApplication::exec()) may cause your user interface to freeze.
The following example runs gzip to compress the string "Qt rocks!", without an event loop:
QProcess gzip;
gzip.start("gzip", QStringList() << "-c");
if (!gzip.waitForStarted())
return false;
gzip.write("Qt rocks!");
gzip.closeWriteChannel();
if (!gzip.waitForFinished())
return false;
QByteArray result = gzip.readAll();
Notes for Windows Users
Some Windows commands (for example, dir) are not provided by separate applications, but by the command interpreter itself. If you attempt to use QProcess to execute these commands directly, it won't work. One possible solution is to execute the command interpreter itself (cmd.exe on some Windows systems), and ask the interpreter to execute the desired command.
Symbian Platform Security Requirements
On Symbian, processes which use the functions kill() or terminate() must have the PowerMgmt platform security capability. If the client process lacks this capability, these functions will fail.
Platform security capabilities are added via the TARGET.CAPABILITY qmake variable.
This enum describes the different exit statuses of QProcess.
See also exitStatus().
This enum describes the process channels used by the running process. Pass one of these values to setReadChannel() to set the current read channel of QProcess.
See also setReadChannel().
This enum describes the process channel modes of QProcess. Pass one of these values to setProcessChannelMode() to set the current read channel mode.
See also setProcessChannelMode().
ForwardedChannels |
QProcess forwards the output of the running process onto the main process. Anything the child process writes to its standard output and standard error will be written to the standard output and standard error of the main process. |
MergedChannels |
QProcess merges the output of the running process into the standard output channel (stdout). The standard error channel (stderr) will not receive any data. The standard output and standard error data of the running process are interleaved. |
SeparateChannels |
QProcess manages the output of the running process, keeping standard output and standard error data in separate internal buffers. You can select the QProcess's current read channel by calling setReadChannel(). This is the default channel mode of QProcess. |
This enum describes the different types of errors that are reported by QProcess.
See also error().
Crashed |
The process crashed some time after starting successfully. |
FailedToStart |
The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program. |
ReadError |
An error occurred when attempting to read from the process. For example, the process may not be running. |
Timedout |
The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again. |
UnknownError |
An unknown error occurred. This is the default return value of error(). |
WriteError |
An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel. |
This enum describes the different states of QProcess.
See also state().
|
protected |
QtCore.QProcess.QProcess | ( | QObject | parent = null | ) |
Constructs a QProcess object with the given parent.
|
virtual |
Reimplemented from QIODevice::atEnd().
Returns true if the process is not running, and no more data is available for reading; otherwise returns false.
Reimplemented from QtCore.QIODevice.
|
virtual |
Reimplemented from QIODevice::bytesAvailable().
Reimplemented from QtCore.QIODevice.
|
virtual |
Reimplemented from QIODevice::bytesToWrite().
Reimplemented from QtCore.QIODevice.
|
virtual |
Reimplemented from QIODevice::canReadLine().
This function operates on the current read channel.
See also readChannel() and setReadChannel().
Reimplemented from QtCore.QIODevice.
|
virtual |
Reimplemented from QIODevice::close().
Closes all communication with the process and kills it. After calling this function, QProcess will no longer emit readyRead(), and data can no longer be read or written.
Reimplemented from QtCore.QIODevice.
new void QtCore.QProcess.CloseReadChannel | ( | QProcess.ProcessChannel | channel | ) |
Closes the read channel channel. After calling this function, QProcess will no longer receive data on the channel. Any data that has already been received is still available for reading.
Call this function to save memory, if you are not interested in the output of the process.
See also closeWriteChannel() and setReadChannel().
new void QtCore.QProcess.CloseWriteChannel | ( | ) |
Schedules the write channel of QProcess to be closed. The channel will close once all data has been written to the process. After calling this function, any attempts to write to the process will fail.
Closing the write channel is necessary for programs that read input data until the channel has been closed. For example, the program "more" is used to display text data in a console on both Unix and Windows. But it will not display the text data until QProcess's write channel has been closed. Example:
QProcess more;
more.start("more");
more.write("Text to display");
more.closeWriteChannel();
// QProcess will emit readyRead() once "more" starts printing
The write channel is implicitly opened when start() is called.
See also closeReadChannel().
|
virtual |
Reimplemented from QtCore.QIODevice.
new void QtCore.QProcess.Dispose | ( | ) |
|
static |
This is an overloaded function.
Starts the program program in a new process. program is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.
|
static |
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.
The environment and working directory are inherited from the calling process.
On Windows, arguments that contain spaces are wrapped in quotes.
If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.
new int QtCore.QProcess.ExitCode | ( | ) |
Returns the exit code of the last process that finished.
new QProcess.ExitStatus QtCore.QProcess.exitStatus | ( | ) |
Returns the exit status of the last process that finished.
On Windows, if the process was terminated with TerminateProcess() from another application this function will still return NormalExit unless the exit code is less than 0.
This function was introduced in Qt 4.1.
|
virtual |
Reimplemented from QIODevice::isSequential().
Reimplemented from QtCore.QIODevice.
new void QtCore.QProcess.Kill | ( | ) |
Kills the current process, causing it to exit immediately.
On Windows, kill() uses TerminateProcess, and on Unix and Mac OS X, the SIGKILL signal is sent to the process.
On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.
Note: Killing running processes from other processes will typically cause a panic in Symbian due to platform security.
See also Symbian Platform Security Requirements and terminate().
new QProcess.ProcessError QtCore.QProcess.OnError | ( | ) |
Returns the type of error that occurred last.
See also state().
|
protected |
Returns the type of error that occurred last.
See also state().
|
protected |
This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished, the buffers in QProcess are still intact. You can still read any data that the process may have written before it finished.
See also exitStatus().
|
protected |
This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished, the buffers in QProcess are still intact. You can still read any data that the process may have written before it finished.
See also exitStatus().
|
protected |
This signal is emitted when the process has made new data available through its standard error channel (stderr). It is emitted regardless of the current read channel.
See also readAllStandardError() and readChannel().
|
protected |
This signal is emitted when the process has made new data available through its standard output channel (stdout). It is emitted regardless of the current read channel.
See also readAllStandardOutput() and readChannel().
|
protected |
This signal is emitted by QProcess when the process has started, and state() returns Running.
|
protected |
new QByteArray QtCore.QProcess.ReadAllStandardError | ( | ) |
Regardless of the current read channel, this function returns all data available from the standard error of the process as a QByteArray.
See also readyReadStandardError(), readAllStandardOutput(), readChannel(), and setReadChannel().
new QByteArray QtCore.QProcess.ReadAllStandardOutput | ( | ) |
Regardless of the current read channel, this function returns all data available from the standard output of the process as a QByteArray.
See also readyReadStandardOutput(), readAllStandardError(), readChannel(), and setReadChannel().
|
protectedvirtual |
Reimplemented from QIODevice::readData().
Implements QtCore.QIODevice.
|
protected |
Sets the current state of the QProcess to the state specified.
See also state().
new void QtCore.QProcess.SetStandardErrorFile | ( | string | fileName, |
QIODevice.OpenModeFlag | mode = QIODevice.OpenModeFlag.Truncate |
||
) |
Redirects the process' standard error to the file fileName. When the redirection is in place, the standard error read channel is closed: reading from it using read() will always fail, as will readAllStandardError(). The file will be appended to if mode is Append, otherwise, it will be truncated.
See setStandardOutputFile() for more information on how the file is opened.
Note: if setProcessChannelMode() was called with an argument of QProcess::MergedChannels, this function has no effect.
This function was introduced in Qt 4.2.
See also setStandardInputFile(), setStandardOutputFile(), and setStandardOutputProcess().
new void QtCore.QProcess.SetStandardInputFile | ( | string | fileName | ) |
Redirects the process' standard input to the file indicated by fileName. When an input redirection is in place, the QProcess object will be in read-only mode (calling write() will result in error).
If the file fileName does not exist at the moment start() is called or is not readable, starting the process will fail.
Calling setStandardInputFile() after the process has started has no effect.
This function was introduced in Qt 4.2.
See also setStandardOutputFile(), setStandardErrorFile(), and setStandardOutputProcess().
new void QtCore.QProcess.SetStandardOutputFile | ( | string | fileName, |
QIODevice.OpenModeFlag | mode = QIODevice.OpenModeFlag.Truncate |
||
) |
Redirects the process' standard output to the file fileName. When the redirection is in place, the standard output read channel is closed: reading from it using read() will always fail, as will readAllStandardOutput().
If the file fileName doesn't exist at the moment start() is called, it will be created. If it cannot be created, the starting will fail.
If the file exists and mode is QIODevice::Truncate, the file will be truncated. Otherwise (if mode is QIODevice::Append), the file will be appended to.
Calling setStandardOutputFile() after the process has started has no effect.
This function was introduced in Qt 4.2.
See also setStandardInputFile(), setStandardErrorFile(), and setStandardOutputProcess().
new void QtCore.QProcess.SetStandardOutputProcess | ( | QProcess | destination | ) |
Pipes the standard output stream of this process to the destination process' standard input.
The following shell command:
command1 | command2
Can be accomplished with QProcesses with the following code:
QProcess process1;
QProcess process2;
process1.setStandardOutputProcess(&process2);
process1.start("command1");
process2.start("command2");
This function was introduced in Qt 4.2.
|
protectedvirtual |
This function is called in the child process context just before the program is executed on Unix or Mac OS X (i.e., after fork(), but before execve()). Reimplement this function to do last minute initialization of the child process. Example:
class SandboxProcess : public QProcess
{
...
protected:
void setupChildProcess();
...
};
void SandboxProcess::setupChildProcess()
{
// Drop all privileges in the child process, and enter
// a chroot jail.
#if defined Q_OS_UNIX
::setgroups(0, 0);
::chroot("/etc/safe");
::chdir("/");
::setgid(safeGid);
::setuid(safeUid);
::umask(0);
#endif
}
You cannot exit the process (by calling exit(), for instance) from this function. If you need to stop the program before it starts execution, your workaround is to emit finished() and then call exit().
Warning: This function is called by QProcess on Unix and Mac OS X only. On Windows and QNX, it is not called.
new void QtCore.QProcess.Start | ( | string | program, |
QIODevice.OpenModeFlag | mode = QIODevice.OpenModeFlag.ReadWrite |
||
) |
Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. The OpenMode is set to mode.
The QProcess object will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, error() will be emitted. If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running.
Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.
Note: No further splitting of the arguments is performed.
Windows: Arguments that contain spaces are wrapped in quotes.
See also pid(), started(), and waitForStarted().
new void QtCore.QProcess.Start | ( | string | program, |
System.Collections.Generic.List< string > | arguments, | ||
QIODevice.OpenModeFlag | mode = QIODevice.OpenModeFlag.ReadWrite |
||
) |
Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. The OpenMode is set to mode.
The QProcess object will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, error() will be emitted. If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running.
Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.
Note: No further splitting of the arguments is performed.
Windows: Arguments that contain spaces are wrapped in quotes.
See also pid(), started(), and waitForStarted().
|
static |
This is an overloaded function.
Starts the program program in a new process. program is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.
The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process.
|
static |
Starts the program program with the given arguments in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.
Note: Arguments that contain spaces are not passed to the process as separate arguments.
Unix: The started process will run in its own session and act like a daemon.
Windows: Arguments that contain spaces are wrapped in quotes. The started process will run as a regular standalone process.
|
static |
Starts the program program with the arguments arguments in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.
Note that arguments that contain spaces are not passed to the process as separate arguments.
Unix: The started process will run in its own session and act like a daemon.
Windows: Arguments that contain spaces are wrapped in quotes. The started process will run as a regular standalone process.
The process will be started in the directory workingDirectory.
Note: On QNX, this may cause all application threads to temporarily freeze.
If the function is successful then *pid is set to the process identifier of the started process.
|
static |
Starts the program program with the arguments arguments in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.
Note that arguments that contain spaces are not passed to the process as separate arguments.
Unix: The started process will run in its own session and act like a daemon.
Windows: Arguments that contain spaces are wrapped in quotes. The started process will run as a regular standalone process.
The process will be started in the directory workingDirectory.
Note: On QNX, this may cause all application threads to temporarily freeze.
If the function is successful then *pid is set to the process identifier of the started process.
new QProcess.ProcessState QtCore.QProcess.State | ( | ) |
Returns the current state of the process.
See also stateChanged() and error().
|
static |
Returns the environment of the calling process as a list of key=value pairs. Example:
QStringList environment = QProcess::systemEnvironment();
// environment = {"PATH=/usr/bin:/usr/local/bin",
// "USER=greg", "HOME=/home/greg"}
This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C library functions like setenv ot putenv have been called.
However, note that repeated calls to this function will recreate the list of environment variables, which is a non-trivial operation.
Note: For new code, it is recommended to use QProcessEnvironment::systemEnvironment()
This function was introduced in Qt 4.1.
See also QProcessEnvironment::systemEnvironment(), environment(), and setEnvironment().
new void QtCore.QProcess.Terminate | ( | ) |
Attempts to terminate the process.
The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).
On Windows, terminate() posts a WM_CLOSE message to all toplevel windows of the process and then to the main thread of the process itself. On Unix and Mac OS X the SIGTERM signal is sent.
Console applications on Windows that do not run an event loop, or whose event loop does not handle the WM_CLOSE message, can only be terminated by calling kill().
On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.
Note: Terminating running processes from other processes will typically cause a panic in Symbian due to platform security.
See also Symbian Platform Security Requirements and kill().
|
static |
|
static |
|
static |
|
static |
|
virtual |
Reimplemented from QIODevice::waitForBytesWritten().
Reimplemented from QtCore.QIODevice.
new bool QtCore.QProcess.WaitForFinished | ( | int | msecs = 30000 | ) |
Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed.
Returns true if the process finished; otherwise returns false (if the operation timed out, if an error occurred, or if this QProcess is already finished).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
If msecs is -1, this function will not time out.
See also finished(), waitForStarted(), waitForReadyRead(), and waitForBytesWritten().
|
virtual |
Reimplemented from QIODevice::waitForReadyRead().
Reimplemented from QtCore.QIODevice.
new bool QtCore.QProcess.WaitForStarted | ( | int | msecs = 30000 | ) |
Blocks until the process has started and the started() signal has been emitted, or until msecs milliseconds have passed.
Returns true if the process was started successfully; otherwise returns false (if the operation timed out or if an error occurred).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
If msecs is -1, this function will not time out.
See also started(), waitForReadyRead(), waitForBytesWritten(), and waitForFinished().
|
protectedvirtual |
Reimplemented from QIODevice::writeData().
Implements QtCore.QIODevice.
|
getprotected |
|
getset |
This function is deprecated.
Returns the environment that QProcess will use when starting a process, or an empty QStringList if no environment has been set using setEnvironment() or setEnvironmentHash(). If no environment has been set, the environment of the calling process will be used.
Note: The environment settings are ignored on Windows CE and Symbian, as there is no concept of an environment.
This function is deprecated.
Sets the environment that QProcess will use when starting a process to the environment specified which consists of a list of key=value pairs.
For example, the following code adds the C:\\BIN directory to the list of executable paths (PATHS) on Windows:
QProcess process;
QStringList env = QProcess::systemEnvironment();
env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin");
process.setEnvironment(env);
process.start("myapp");
Note: This function is less efficient than the setProcessEnvironment() function.
|
addremove |
Returns the type of error that occurred last.
See also state().
|
addremove |
This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished, the buffers in QProcess are still intact. You can still read any data that the process may have written before it finished.
See also exitStatus().
|
addremove |
|
getset |
Returns the additional native command line arguments for the program.
Note: This function is available only on the Windows and Symbian platforms.
This function was introduced in Qt 4.7.
This is an overloaded function.
Sets additional native command line arguments for the program.
On operating systems where the system API for passing command line arguments to a subprocess natively uses a single string, one can conceive command lines which cannot be passed via QProcess's portable list-based API. In such cases this function must be used to set a string which is appended to the string composed from the usual argument list, with a delimiting space.
Note: This function is available only on the Windows and Symbian platforms.
This function was introduced in Qt 4.7.
|
getset |
Returns the channel mode of the QProcess standard output and standard error channels.
This function was introduced in Qt 4.2.
Sets the channel mode of the QProcess standard output and standard error channels to the mode specified. This mode will be used the next time start() is called. For example:
QProcess builder;
builder.setProcessChannelMode(QProcess::MergedChannels);
builder.start("make", QStringList() << "-j2");
if (!builder.waitForFinished())
qDebug() << "Make failed:" << builder.errorString();
else
qDebug() << "Make output:" << builder.readAll();
This function was introduced in Qt 4.2.
|
getset |
Returns the environment that QProcess will use when starting a process, or an empty object if no environment has been set using setEnvironment() or setProcessEnvironment(). If no environment has been set, the environment of the calling process will be used.
Note: The environment settings are ignored on Windows CE, as there is no concept of an environment.
This function was introduced in Qt 4.6.
Sets the environment that QProcess will use when starting a process to the environment object.
For example, the following code adds the C:\\BIN directory to the list of executable paths (PATHS) on Windows and sets TMPDIR:
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
env.insert("PATH", env.value("Path") + ";C:\\Bin");
process.setProcessEnvironment(env);
process.start("myapp");
Note how, on Windows, environment variable names are case-insensitive.
This function was introduced in Qt 4.6.
|
getset |
|
getset |
Returns the read channel mode of the QProcess. This function is equivalent to processChannelMode()
Use setProcessChannelMode(mode) instead.
|
addremove |
This signal is emitted when the process has made new data available through its standard error channel (stderr). It is emitted regardless of the current read channel.
See also readAllStandardError() and readChannel().
|
addremove |
This signal is emitted when the process has made new data available through its standard output channel (stdout). It is emitted regardless of the current read channel.
See also readAllStandardOutput() and readChannel().
|
addremove |
This signal is emitted by QProcess when the process has started, and state() returns Running.
|
addremove |
|
staticget |
|
getset |
If QProcess has been assigned a working directory, this function returns the working directory that the QProcess will enter before the program has started. Otherwise, (i.e., no directory has been assigned,) an empty string is returned, and QProcess will use the application's current working directory instead.
Sets the working directory to dir. QProcess will start the process in this directory. The default behavior is to start the process in the working directory of the calling process.
Note: The working directory setting is ignored on Symbian; the private directory of the process is considered its working directory.
Note: On QNX, this may cause all application threads to temporarily freeze.