|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QIODevice
com.trolltech.qt.core.QProcess
public class QProcess
The QProcess class is used to start external programs and to communicate with them. To start a process, pass the name and command line arguments of the program you want to run as arguments to start()
. For example:
QObject parent = QApplication.instance(); ... String program = "./path/to/my/favorite/program"; List<String> arguments = new Vector<String>(); arguments.add("-style"); arguments.add("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, 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.
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.
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.The following example runs gzip to compress the string "Qt rocks!", without an event loop:
QProcess gzip = new QProcess(); List<String> args = new Vector<String>(); args.add("-c"); gzip.start("gzip", args); if (!gzip.waitForStarted()) return false; gzip.write(new QByteArray("Qt rocks!")); gzip.closeWriteChannel(); if (!gzip.waitForFinished()) return false; QByteArray result = gzip.readAll();
QBuffer
, QFile
, and QTcpSocket
.
Nested Class Summary | |
---|---|
static class |
QProcess.DetachedProcessInfo
|
static class |
QProcess.ExitStatus
This enum describes the different exit statuses of QProcess . |
static class |
QProcess.ProcessChannel
|
static class |
QProcess.ProcessChannelMode
This enum describes the process channel modes of QProcess . |
static class |
QProcess.ProcessError
This enum describes the different types of errors that are reported by QProcess . |
static class |
QProcess.ProcessState
This enum describes the different states of QProcess . |
Nested classes/interfaces inherited from class com.trolltech.qt.core.QIODevice |
---|
QIODevice.OpenMode, QIODevice.OpenModeFlag |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
error
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
finished
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal2 |
finishedWithStatusCode
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal0 |
readyReadStandardError
This signal is emitted when the process has made new data available through its standard error channel (stderr). |
QSignalEmitter.Signal0 |
readyReadStandardOutput
This signal is emitted when the process has made new data available through its standard output channel (stdout). |
QSignalEmitter.Signal0 |
started
This signal is emitted by QProcess when the process has started, and state() returns Running . |
QSignalEmitter.Signal1 |
stateChanged
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.core.QIODevice |
---|
aboutToClose, bytesWritten, readChannelFinished, readyRead |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QProcess()
Constructs a QProcess object with the given parent. |
|
QProcess(QObject parent)
Constructs a QProcess object with the given parent. |
Method Summary | |
---|---|
void |
closeReadChannel(QProcess.ProcessChannel channel)
Closes the read channel channel. |
void |
closeWriteChannel()
Schedules the write channel of QProcess to be closed. |
java.util.List |
environment()
Returns the environment that QProcess will use when starting a process, or an empty QStringList if no environment has been set using setEnvironment() . |
QProcess.ProcessError |
error()
Returns the type of error that occurred last. |
static int |
execute(java.lang.String program)
Starts the program program in a new process. |
static int |
execute(java.lang.String program,
java.util.List arguments)
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. |
int |
exitCode()
Returns the exit code of the last process that finished. |
QProcess.ExitStatus |
exitStatus()
Returns the exit status of the last process that finished. |
void |
kill()
Kills the current process, causing it to exit immediately. |
QProcess.ProcessChannelMode |
processChannelMode()
Returns the channel mode of the QProcess standard output and standard error channels. |
QByteArray |
readAllStandardError()
Regardless of the current read channel, this function returns all data available from the standard error of the process as a QByteArray . |
QByteArray |
readAllStandardOutput()
Regardless of the current read channel, this function returns all data available from the standard output of the process as a QByteArray . |
QProcess.ProcessChannel |
readChannel()
Returns the current read channel of the QProcess. |
void |
setEnvironment(java.util.List environment)
Sets the environment that QProcess will use when starting a process to the environment specified which consists of a list of key=value pairs. |
void |
setProcessChannelMode(QProcess.ProcessChannelMode mode)
Sets the channel mode of the QProcess standard output and standard error channels to the mode specified. |
protected void |
setProcessState(QProcess.ProcessState state)
Sets the current state of the QProcess to the state specified. |
void |
setReadChannel(QProcess.ProcessChannel channel)
Sets the current read channel of the QProcess to the given channel. |
void |
setStandardErrorFile(java.lang.String fileName)
Redirects the process' standard error to the file fileName. |
void |
setStandardErrorFile(java.lang.String fileName,
QIODevice.OpenMode mode)
Redirects the process' standard error to the file fileName. |
void |
setStandardErrorFile(java.lang.String fileName,
QIODevice.OpenModeFlag[] mode)
|
void |
setStandardInputFile(java.lang.String fileName)
Redirects the process' standard input to the file indicated by fileName. |
void |
setStandardOutputFile(java.lang.String fileName)
Redirects the process' standard output to the file fileName. |
void |
setStandardOutputFile(java.lang.String fileName,
QIODevice.OpenMode mode)
Redirects the process' standard output to the file fileName. |
void |
setStandardOutputFile(java.lang.String fileName,
QIODevice.OpenModeFlag[] mode)
|
void |
setStandardOutputProcess(QProcess destination)
Pipes the standard output stream of this process to the destination process' standard input. |
protected void |
setupChildProcess()
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()). |
void |
setWorkingDirectory(java.lang.String dir)
Sets the working directory to dir. |
void |
start(java.lang.String program)
Starts the program program in a new process. |
void |
start(java.lang.String program,
java.util.List arguments)
Starts the program program in a new process, passing the command line arguments in arguments. |
void |
start(java.lang.String program,
java.util.List arguments,
QIODevice.OpenMode mode)
Starts the program program in a new process, passing the command line arguments in arguments. |
void |
start(java.lang.String program,
java.util.List arguments,
QIODevice.OpenModeFlag[] mode)
|
void |
start(java.lang.String program,
QIODevice.OpenMode mode)
Starts the program program in a new process. |
void |
start(java.lang.String program,
QIODevice.OpenModeFlag[] mode)
|
static boolean |
startDetached(java.lang.String program)
Starts the program program in a new process. |
static boolean |
startDetached(java.lang.String program,
java.util.List arguments)
Starts the program program with the arguments arguments in a new process, and detaches from it. |
static QProcess.DetachedProcessInfo |
startDetached(java.lang.String program,
java.util.List arguments,
java.lang.String workingDirectory)
|
QProcess.ProcessState |
state()
Returns the current state of the process. |
static java.util.List |
systemEnvironment()
Returns the environment of the calling process as a list of key=value pairs. |
void |
terminate()
Attempts to terminate the process. |
boolean |
waitForFinished()
Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed. |
boolean |
waitForFinished(int msecs)
Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed. |
boolean |
waitForStarted()
Blocks until the process has started and the started() signal has been emitted, or until msecs milliseconds have passed. |
boolean |
waitForStarted(int msecs)
Blocks until the process has started and the started() signal has been emitted, or until msecs milliseconds have passed. |
java.lang.String |
workingDirectory()
If QProcess has been assigned a working directory, this function returns the working directory that the QProcess will enter before the program has started. |
Methods inherited from class com.trolltech.qt.core.QIODevice |
---|
atEnd, bytesAvailable, bytesToWrite, canReadLine, close, errorString, getByte, isOpen, isReadable, isSequential, isTextModeEnabled, isWritable, open, open, openMode, peek, peek, pos, putByte, read, read, readAll, readData, readLine, readLine, readLine, readLineData, reset, seek, setErrorString, setOpenMode, setOpenMode, setTextModeEnabled, size, ungetByte, waitForBytesWritten, waitForReadyRead, write, write, writeData |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 error
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QProcess$ProcessError(named: error)>:
This signal is emitted when an error occurs with the process. The specified error describes the type of error that occurred.
public final QSignalEmitter.Signal1 finished
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: exitCode)>:
Use finished(int exitCode, QProcess::ExitStatus
status) instead.
public final QSignalEmitter.Signal2 finishedWithStatusCode
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: exitCode), >:
Use finished(int exitCode, QProcess::ExitStatus
status) instead.
public final QSignalEmitter.Signal0 readyReadStandardError
read channel
. readAllStandardError()
, and readChannel()
.
public final QSignalEmitter.Signal0 readyReadStandardOutput
read channel
. readAllStandardOutput()
, and readChannel()
.
public final QSignalEmitter.Signal0 started
state()
returns Running
.
public final QSignalEmitter.Signal1 stateChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QProcess$ProcessState(named: newState)>:
This signal is emitted whenever the state of QProcess changes. The newState argument is the state QProcess changed to.
Constructor Detail |
---|
public QProcess()
public QProcess(QObject parent)
Method Detail |
---|
public final void closeReadChannel(QProcess.ProcessChannel channel)
Call this function to save memory, if you are not interested in the output of the process.
closeWriteChannel()
, and setReadChannel()
.
public final void closeWriteChannel()
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 = new QProcess(); more.start("more"); more.write(new QByteArray("Text to display")); more.closeWriteChannel(); // QProcess will emit readyRead() once "more" starts printingThe write channel is implicitly opened when
start()
is called. closeReadChannel()
.
public final java.util.List environment()
setEnvironment()
. 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.
setEnvironment()
, and systemEnvironment()
.
public final QProcess.ProcessError error()
state()
.
public final int exitCode()
public final QProcess.ExitStatus exitStatus()
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.
public final void kill()
On Windows, kill()
uses TerminateProcess, and on Unix and Mac OS X, the SIGKILL signal is sent to the process.
terminate()
.
public final QProcess.ProcessChannelMode processChannelMode()
setProcessChannelMode()
, setReadChannelMode(), ProcessChannelMode
, and setReadChannel()
.
public final QByteArray readAllStandardError()
QByteArray
. readyReadStandardError()
, readAllStandardOutput()
, readChannel()
, and setReadChannel()
.
public final QByteArray readAllStandardOutput()
QByteArray
. readyReadStandardOutput()
, readAllStandardError()
, readChannel()
, and setReadChannel()
.
public final QProcess.ProcessChannel readChannel()
setReadChannel()
.
public final void setEnvironment(java.util.List environment)
For example, the following code adds the C:\\BIN directory to the list of executable paths (PATHS) on Windows:
QProcess process = new QProcess(); List<String> env = QProcess.systemEnvironment(); env.add("TMPDIR=C:\\MyApp\\temp"); // Add an environment variable for (String str : env) str.replaceAll("^PATH=(.*)", "PATH=\\1;C:\\Bin"); process.setEnvironment(env); process.start("myapp");
environment()
, and systemEnvironment()
.
public final void setProcessChannelMode(QProcess.ProcessChannelMode mode)
start()
is called. For example: QProcess builder = new QProcess(); builder.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels); List<String> arguments = new Vector<String>(); arguments.add("-j2"); builder.start("make", arguments); if (!builder.waitForFinished()) System.err.println("Make failed:" + builder.errorString()); else System.err.println("Make output:" + builder.readAll());
processChannelMode()
, readChannelMode(), ProcessChannelMode
, and setReadChannel()
.
protected final void setProcessState(QProcess.ProcessState state)
state()
.
public final void setReadChannel(QProcess.ProcessChannel channel)
read()
, readAll()
, readLine()
, and getChar(). It also determines which channel triggers QProcess to emit readyRead()
. readChannel()
.
public final void setStandardErrorFile(java.lang.String fileName, QIODevice.OpenModeFlag[] mode)
public final void setStandardErrorFile(java.lang.String fileName)
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.
setStandardInputFile()
, setStandardOutputFile()
, and setStandardOutputProcess()
.
public final void setStandardErrorFile(java.lang.String fileName, QIODevice.OpenMode mode)
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.
setStandardInputFile()
, setStandardOutputFile()
, and setStandardOutputProcess()
.
public final void setStandardInputFile(java.lang.String fileName)
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.
setStandardOutputFile()
, setStandardErrorFile()
, and setStandardOutputProcess()
.
public final void setStandardOutputFile(java.lang.String fileName, QIODevice.OpenModeFlag[] mode)
public final void setStandardOutputFile(java.lang.String fileName)
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.
setStandardInputFile()
, setStandardErrorFile()
, and setStandardOutputProcess()
.
public final void setStandardOutputFile(java.lang.String fileName, QIODevice.OpenMode mode)
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.
setStandardInputFile()
, setStandardErrorFile()
, and setStandardOutputProcess()
.
public final void setStandardOutputProcess(QProcess destination)
The following shell command:
command1 | command2Can be accomplished with QProcesses with the following code:
QProcess process1 = new QProcess(); QProcess process2 = new QProcess(); process1.setStandardOutputProcess(process2); process1.start("command1"); process2.start("command2");
public final void setWorkingDirectory(java.lang.String dir)
workingDirectory()
, and start()
.
public final void start(java.lang.String program, QIODevice.OpenModeFlag[] mode)
public final void start(java.lang.String program)
QProcess process = new QProcess(); process.start("del /s *.txt"); // same as process.start("del", List<String>() << "/s" << "*.txt"); // ...The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example:
QProcess process = new QProcess(); process.start("dir \"My Documents\"");Note that, on Windows, quotes need to be both escaped and quoted. For example, the above code would be specified in the following way to ensure that "My Documents" is used as the argument to the dir executable:
QProcess process = new QProcess(); process.start("dir \"\"\"My Documents\"\"\"");The OpenMode is set to mode.
public final void start(java.lang.String program, QIODevice.OpenMode mode)
QProcess process = new QProcess(); process.start("del /s *.txt"); // same as process.start("del", List<String>() << "/s" << "*.txt"); // ...The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example:
QProcess process = new QProcess(); process.start("dir \"My Documents\"");Note that, on Windows, quotes need to be both escaped and quoted. For example, the above code would be specified in the following way to ensure that "My Documents" is used as the argument to the dir executable:
QProcess process = new QProcess(); process.start("dir \"\"\"My Documents\"\"\"");The OpenMode is set to mode.
public final void start(java.lang.String program, java.util.List arguments, QIODevice.OpenModeFlag[] mode)
public final void start(java.lang.String program, java.util.List arguments)
On Windows, arguments that contain spaces are wrapped in quotes.
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.
public final void start(java.lang.String program, java.util.List arguments, QIODevice.OpenMode mode)
started()
; otherwise, error()
will be emitted. On Windows, arguments that contain spaces are wrapped in quotes.
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.
started()
, and waitForStarted()
.
public final QProcess.ProcessState state()
stateChanged()
, and error()
.
public final void terminate()
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()
.
kill()
.
public final boolean waitForFinished()
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 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.
finished()
, waitForStarted()
, waitForReadyRead()
, and waitForBytesWritten()
.
public final boolean waitForFinished(int msecs)
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 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.
finished()
, waitForStarted()
, waitForReadyRead()
, and waitForBytesWritten()
.
public final boolean waitForStarted()
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.
started()
, waitForReadyRead()
, waitForBytesWritten()
, and waitForFinished()
.
public final boolean waitForStarted(int msecs)
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.
started()
, waitForReadyRead()
, waitForBytesWritten()
, and waitForFinished()
.
public final java.lang.String workingDirectory()
setWorkingDirectory()
.
protected void setupChildProcess()
This code is not relevant for Qt Jambi. class SandboxProcess extends QProcess { protected void setupChildProcess() { // Drop all privileges in the child process, and enter // a chroot jail. if (QSysInfo.operatingSystem() == QSysInfo.OS_LINUX) { setgroups(0, 0); chroot("/etc/safe"); chdir("/"); setgid(safeGid); setuid(safeUid); } } }Warning: This function is called by QProcess on Unix and Mac OS X only. On Windows, it is not called.
public static int execute(java.lang.String program)
public static int execute(java.lang.String program, java.util.List arguments)
The environment and working directory are inherited by the calling process.
On Windows, arguments that contain spaces are wrapped in quotes.
public static boolean startDetached(java.lang.String program)
The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process.
public static boolean startDetached(java.lang.String program, java.util.List arguments)
On Unix, the started process will run in its own session and act like a daemon. On Windows, it will run as a regular standalone process.
On Windows, arguments that contain spaces are wrapped in quotes.
public static java.util.List systemEnvironment()
List<String> environment = QProcess.systemEnvironment(); // environment = {"PATH=/usr/bin:/usr/local/bin", // "USER=greg", "HOME=/home/greg"}
environment()
, and setEnvironment()
.
public static QProcess.DetachedProcessInfo startDetached(java.lang.String program, java.util.List arguments, java.lang.String workingDirectory)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |