Q3Process Class Reference |
Constant | Value | Description |
---|---|---|
Q3Process::Stdin | 0x01 | Data can be written to the process's standard input. |
Q3Process::Stdout | 0x02 | Data can be read from the process's standard output. |
Q3Process::Stderr | 0x04 | Data can be read from the process's standard error. |
Q3Process::DupStderr | 0x08 | Both the process's standard error output and its standard output are written to its standard output. (Like Unix's dup2().) This means that nothing is sent to the standard error output. This is especially useful if your application requires that the output on standard output and on standard error must be read in the same order that they are produced. This is a flag, so to activate it you must pass Stdout|Stderr|DupStderr, or Stdin|Stdout|Stderr|DupStderr if you want to provide input, to the setCommunication() call. |
See also setCommunication() and communication().
Constructs a Q3Process object. The parent and name parameters are passed to the QObject constructor.
See also setArguments(), addArgument(), and start().
Constructs a Q3Process with arg0 as the command to be executed. The parent and name parameters are passed to the QObject constructor.
The process is not started. You must call start() or launch() to start the process.
See also setArguments(), addArgument(), and start().
Constructs a Q3Process with args as the arguments of the process. The first element in the list is the command to be executed. The other elements in the list are the arguments to this command. The parent and name parameters are passed to the QObject constructor.
The process is not started. You must call start() or launch() to start the process.
See also setArguments(), addArgument(), and start().
Destroys the instance.
If the process is running, it is <b>not</b> terminated! The standard input, standard output and standard error of the process are closed.
You can connect the destroyed() signal to the kill() slot, if you want the process to be terminated automatically when the instance is destroyed.
See also tryTerminate() and kill().
Adds arg to the end of the list of arguments.
The first element in the list of arguments is the command to be executed; the following elements are the command's arguments.
See also arguments() and setArguments().
Returns the list of arguments that are set for the process. Arguments can be specified with the constructor or with the functions setArguments() and addArgument().
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myProcess.arguments(); QStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also setArguments() and addArgument().
Returns true if it's possible to read an entire line of text from standard error at this time; otherwise returns false.
See also readLineStderr() and canReadLineStdout().
Returns true if it's possible to read an entire line of text from standard output at this time; otherwise returns false.
See also readLineStdout() and canReadLineStderr().
Clears the list of arguments that are set for the process.
See also setArguments() and addArgument().
Closes the process's standard input.
This function also deletes any pending data that has not been written to standard input.
See also wroteToStdin().
Returns the communication required with the process, i.e. some combination of the Communication flags.
See also setCommunication().
Returns the exit status of the process or 0 if the process is still running. This function returns immediately and does not wait until the process is finished.
If normalExit() is false (e.g. if the program was killed or crashed), this function returns 0, so you should check the return value of normalExit() before relying on this value.
See also normalExit() and processExited().
Returns true if the process is running; otherwise returns false.
See also normalExit(), exitStatus(), and processExited().
Terminates the process. This is not a safe way to end a process since the process will not be able to do any cleanup. tryTerminate() is safer, but processes can ignore a tryTerminate().
The nice way to end a process and to be sure that it is finished, is to do something like this:
process->tryTerminate(); QTimer::singleShot( 5000, process, SLOT( kill() ) );
This tries to terminate the process the nice way. If the process is still running after 5 seconds, it terminates the process the hard way. The timeout should be chosen depending on the time the process needs to do all its cleanup: use a higher value if the process is likely to do a lot of computation or I/O on cleanup.
The slot returns immediately: it does not wait until the process has finished. When the process terminates, the processExited() signal is emitted.
See also tryTerminate() and processExited().
Runs the process and writes the data buf to the process's standard input. If all the data is written to standard input, standard input is closed. The command is searched for in the path for executable programs; you can also use an absolute path in the command itself.
If env is null, then the process is started with the same environment as the starting process. If env is non-null, then the values in the string list are interpreted as environment setttings of the form key=value and the process is started with these environment settings. For convenience, there is a small exception to this rule under Unix: if env does not contain any settings for the environment variable LD_LIBRARY_PATH, then this variable is inherited from the starting process.
Returns true if the process could be started; otherwise returns false.
Note that you should not use the slots writeToStdin() and closeStdin() on processes started with launch(), since the result is not well-defined. If you need these slots, use start() instead.
The process may or may not read the buf data sent to its standard input.
You can call this function even when a process that was started with this instance is still running. Be aware that if you do this the standard input of the process that was launched first will be closed, with any pending data being deleted, and the process will be left to run out of your control. Similarly, if the process could not be started the standard input will be closed and the pending data deleted. (On operating systems that have zombie processes, Qt will also wait() on the old process.)
The object emits the signal launchFinished() when this function call is finished. If the start was successful, this signal is emitted after all the data has been written to standard input. If the start failed, then this signal is emitted immediately.
See also start() and launchFinished().
This is an overloaded member function, provided for convenience.
The data buf is written to standard input with writeToStdin() using the QString::local8Bit() representation of the strings.
This signal is emitted when the process was started with launch(). If the start was successful, this signal is emitted after all the data has been written to standard input. If the start failed, then this signal is emitted immediately.
This signal is especially useful if you want to know when you can safely delete the Q3Process object when you are not interested in reading from standard output or standard error.
See also launch() and QObject::deleteLater().
Returns true if the process has exited normally; otherwise returns false. This implies that this function returns false if the process is still running.
See also isRunning(), exitStatus(), and processExited().
This signal is emitted when the process has exited.
See also isRunning(), normalExit(), exitStatus(), start(), and launch().
Returns platform dependent information about the process. This can be used together with platform specific system calls.
Under Unix the return value is the PID of the process, or -1 if no process belongs to this object.
Under Windows it is a pointer to the PROCESS_INFORMATION struct, or 0 if no process is belongs to this object.
Use of this function's return value is likely to be non-portable.
Reads a line of text from standard error, excluding any trailing newline or carriage return characters and returns it. Returns an empty string if canReadLineStderr() returns false.
By default, the text is interpreted to be in Latin-1 encoding. If you need other codecs, you can set a different codec with QTextCodec::setCodecForCStrings().
See also canReadLineStderr(), readyReadStderr(), readStderr(), and readLineStdout().
Reads a line of text from standard output, excluding any trailing newline or carriage return characters, and returns it. Returns an empty string if canReadLineStdout() returns false.
By default, the text is interpreted to be in Latin-1 encoding. If you need other codecs, you can set a different codec with QTextCodec::setCodecForCStrings().
See also canReadLineStdout(), readyReadStdout(), readStdout(), and readLineStderr().
Reads the data that the process has written to standard error. When new data is written to standard error, the class emits the signal readyReadStderr().
If there is no data to read, this function returns a QByteArray of size 0: it does not wait until there is something to read.
See also readyReadStderr(), readLineStderr(), readStdout(), and writeToStdin().
Reads the data that the process has written to standard output. When new data is written to standard output, the class emits the signal readyReadStdout().
If there is no data to read, this function returns a QByteArray of size 0: it does not wait until there is something to read.
See also readyReadStdout(), readLineStdout(), readStderr(), and writeToStdin().
This signal is emitted when the process has written data to standard error. You can read the data with readStderr().
Note that this signal is only emitted when there is new data and not when there is old, but unread data. In the slot connected to this signal, you should always read everything that is available at that moment to make sure that you don't lose any data.
See also readStderr(), readLineStderr(), and readyReadStdout().
This signal is emitted when the process has written data to standard output. You can read the data with readStdout().
Note that this signal is only emitted when there is new data and not when there is old, but unread data. In the slot connected to this signal, you should always read everything that is available at that moment to make sure that you don't lose any data.
See also readStdout(), readLineStdout(), and readyReadStderr().
Sets args as the arguments for the process. The first element in the list is the command to be executed. The other elements in the list are the arguments to the command. Any previous arguments are deleted.
Q3Process does not perform argument substitutions; for example, if you specify "*" or "$DISPLAY", these values are passed to the process literally. If you want to have the same behavior as the shell provides, you must do the substitutions yourself; i.e. instead of specifying a "*" you must specify the list of all the filenames in the current directory, and instead of "$DISPLAY" you must specify the value of the environment variable DISPLAY.
Note for Windows users. The standard Windows shells, e.g. command.com and cmd.exe, do not perform file globbing, i.e. they do not convert a "*" on the command line into a list of files in the current directory. For this reason most Windows applications implement their own file globbing, and as a result of this, specifying an argument of "*" for a Windows application is likely to result in the application performing a file glob and ending up with a list of filenames.
See also arguments() and addArgument().
Sets commFlags as the communication required with the process.
commFlags is a bitwise OR of the flags defined by the Communication enum.
The default is Stdin|Stdout|Stderr.
See also communication().
Sets dir as the working directory for processes. This does not affect running processes; only processes that are started afterwards are affected.
Setting the working directory is especially useful for processes that try to access files with relative paths.
See also workingDirectory() and start().
Tries to run a process for the command and arguments that were specified with setArguments(), addArgument() or that were specified in the constructor. The command is searched for in the path for executable programs; you can also use an absolute path in the command itself.
If env is null, then the process is started with the same environment as the starting process. If env is non-null, then the values in the stringlist are interpreted as environment setttings of the form key=value and the process is started in these environment settings. For convenience, there is a small exception to this rule: under Unix, if env does not contain any settings for the environment variable LD_LIBRARY_PATH, then this variable is inherited from the starting process; under Windows the same applies for the environment variable PATH.
Returns true if the process could be started; otherwise returns false.
You can write data to the process's standard input with writeToStdin(). You can close standard input with closeStdin() and you can terminate the process with tryTerminate(), or with kill().
You can call this function even if you've used this instance to create a another process which is still running. In such cases, Q3Process closes the old process's standard input and deletes pending data, i.e., you lose all control over the old process, but the old process is not terminated. This applies also if the process could not be started. (On operating systems that have zombie processes, Qt will also wait() on the old process.)
See also launch() and closeStdin().
Asks the process to terminate. Processes can ignore this if they wish. If you want to be certain that the process really terminates, you can use kill() instead.
The slot returns immediately: it does not wait until the process has finished. When the process terminates, the processExited() signal is emitted.
See also kill() and processExited().
Returns the working directory that was set with setWorkingDirectory(), or the current directory if none has been explicitly set.
See also setWorkingDirectory() and QDir::current().
Writes the data buf to the process's standard input. The process may or may not read this data.
This function returns immediately; the Q3Process class might write the data at a later point (you must enter the event loop for this to occur). When all the data is written to the process, the signal wroteToStdin() is emitted. This does not mean that the process actually read the data, since this class only detects when it was able to write the data to the operating system.
See also wroteToStdin(), closeStdin(), readStdout(), and readStderr().
This is an overloaded member function, provided for convenience.
The string buf is handled as text using the QString::local8Bit() representation.
This signal is emitted if the data sent to standard input (via writeToStdin()) was actually written to the process. This does not imply that the process really read the data, since this class only detects when it was able to write the data to the operating system. But it is now safe to close standard input without losing pending data.
See also writeToStdin() and closeStdin().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com