PySide6.QtCore.QProcess¶
- class QProcess¶
- The - QProcessclass is used to start external programs and to communicate with them. More_…- Synopsis¶- Methods¶- def - __init__()
- def - arguments()
- def - environment()
- def - error()
- def - exitCode()
- def - exitStatus()
- def - processId()
- def - program()
- def - readChannel()
- def - setArguments()
- def - setEnvironment()
- def - setProgram()
- def - setReadChannel()
- def - start()
- def - startCommand()
- def - startDetached()
- def - state()
- def - waitForStarted()
 - Slots¶- def - kill()
- def - terminate()
 - Signals¶- def - errorOccurred()
- def - finished()
- def - started()
- def - stateChanged()
 - Static functions¶- def - execute()
- def - nullDevice()
- def - splitCommand()
- def - startDetached()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - 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.- Alternatively, you can set the program to run with - setProgram()and- setArguments(), and then call- start()or- open().- For example, the following code snippet runs the analog clock example in the Fusion style on X11 platforms by passing strings containing “-style” and “fusion” as two items in the list of arguments: - parent = QObject() ... program = "./path/to/Qt/examples/widgets/analogclock" arguments = QStringList() arguments << "-style" << "fusion" myProcess = QProcess(parent) myProcess.start(program, arguments) - QProcessthen enters the- Startingstate, and when the program has started,- QProcessenters the- Runningstate and emits- started().- QProcessallows 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,- QProcesscan also be used as an input source for QXmlReader, or for generating data to be uploaded using QNetworkAccessManager.- When the process exits, - QProcessreenters the- NotRunningstate (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,- QProcesswill emit the- errorOccurred()signal. You can also call- error()to find the type of error that occurred last, and- state()to find the current process state.- Note - QProcessis not supported on VxWorks, iOS, tvOS, or watchOS.- Finding the Executable¶- The program to be run can be set either by calling - setProgram()or directly in the- start()call. The effect of calling- start()with the program name and arguments is equivalent to calling- setProgram()and- setArguments()before that function and then calling the overload without those parameters.- QProcessinterprets the program name in one of three different ways, similar to how Unix shells and the Windows command interpreter operate in their own command-lines:- If the program name is an absolute path, then that is the exact executable that will be launched and - QProcessperforms no searching.
- If the program name is a relative path with more than one path component (that is, it contains at least one slash), the starting directory where that relative path is searched is OS-dependent: on Windows, it’s the parent process’ current working dir, while on Unix it’s the one set with - setWorkingDirectory().
- If the program name is a plain file name with no slashes, the behavior is operating-system dependent. On Unix systems, - QProcesswill search the- PATHenvironment variable; on Windows, the search is performed by the OS and will first the parent process’ current directory before the- PATHenvironment variable (see the documentation for CreateProcess for the full list).
 - To avoid platform-dependent behavior or any issues with how the current application was launched, it is advisable to always pass an absolute path to the executable to be launched. For auxiliary binaries shipped with the application, one can construct such a path starting with - applicationDirPath(). Similarly, to explicitly run an executable that is to be found relative to the directory set with- setWorkingDirectory(), use a program path starting with “./” or “../” as the case may be.- On Windows, the “.exe” suffix is not required for most uses, except those outlined in the CreateProcess documentation. Additionally, - QProcesswill convert the Unix-style forward slashes to Windows path backslashes for the program name. This allows code using- QProcessto be written in a cross-platform manner, as shown in the examples above.- QProcessdoes not support directly executing Unix shell or Windows command interpreter built-in functions, such as- cmd.exe's- dircommand or the Bourne shell’s- export. On Unix, even though many shell built-ins are also provided as separate executables, their behavior may differ from those implemented as built-ins. To run those commands, one should explicitly execute the interpreter with suitable options. For Unix systems, launch “/bin/sh” with two arguments: “-c” and a string with the command-line to be run. For Windows, due to the non-standard way- cmd.exeparses its command-line, use- setNativeArguments()(for example, “/c dir d:”).- Environment variables¶- The - QProcessAPI offers methods to manipulate the environment variables that the child process will see. By default, the child process will have a copy of the current process environment variables that exist at the time the- start()function is called. This means that any modifications performed using- qputenv()prior to that call will be reflected in the child process’ environment. Note that- QProcessmakes no attempt to prevent race conditions with- qputenv()happening in other threads, so it is recommended to avoid- qputenv()after the application’s initial start up.- The environment for a specific child can be modified using the - processEnvironment()and- setProcessEnvironment()functions, which use the- QProcessEnvironmentclass. By default,- processEnvironment()will return an object for which- inheritsFromParent()is true. Setting an environment that does not inherit from the parent will cause- QProcessto use exactly that environment for the child when it is started.- The normal scenario starts from the current environment by calling - systemEnvironment()and then proceeds to adding, changing, or removing specific variables. The resulting variable roster can then be applied to a- QProcesswith- setProcessEnvironment().- It is possible to remove all variables from the environment or to start from an empty environment, using the QProcessEnvironment() default constructor. This is not advisable outside of controlled and system-specific conditions, as there may be system variables that are set in the current process environment and are required for proper execution of the child process. - On Windows, - QProcesswill copy the current process’- "PATH"and- "SystemRoot"environment variables if they were unset. It is not possible to unset them completely, but it is possible to set them to empty values. Setting- "PATH"to empty on Windows will likely cause the child process to fail to start.- 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().- QProcessemits- 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- QProcessis the process’s output, and what we write becomes the process’s input.- QProcesscan 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- MergedChannelsbefore starting the process to activate this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing- ForwardedChannelsas the argument. It is also possible to forward only one of the output channels - typically one would use- ForwardedErrorChannel, but- ForwardedOutputChannelalso exists. Note that using channel forwarding is typically a bad idea in GUI applications - you should present errors graphically instead.- Certain processes need special environment settings in order to operate. You can set environment variables for your process by calling - setProcessEnvironment(). To set a working directory, call- setWorkingDirectory(). By default, processes are run in the current working directory of the calling process.- The positioning and the screen Z-order of windows belonging to GUI applications started with - QProcessare controlled by the underlying windowing system. For Qt 5 applications, the positioning can be specified using the- -qwindowgeometrycommand line option; X11 applications generally accept a- -geometrycommand line option.- Synchronous Process API¶- QProcessprovides 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 - gzipto compress the string “Qt rocks!”, without an event loop:- gzip = QProcess() gzip.start("gzip", QStringList() << "-c") if not gzip.waitForStarted(): return False gzip.write("Qt rocks!") gzip.closeWriteChannel() if not gzip.waitForFinished(): return False result = gzip.readAll() - See also - class ProcessError¶
- This enum describes the different types of errors that are reported by - QProcess.- Constant - Description - QProcess.FailedToStart - The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program. - QProcess.Crashed - The process crashed some time after starting successfully. - QProcess.Timedout - The last waitFor…() function timed out. The state of - QProcessis unchanged, and you can try calling waitFor…() again.- QProcess.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. - QProcess.ReadError - An error occurred when attempting to read from the process. For example, the process may not be running. - QProcess.UnknownError - An unknown error occurred. This is the default return value of - error().- See also 
 - class ProcessState¶
- This enum describes the different states of - QProcess.- Constant - Description - QProcess.NotRunning - The process is not running. - QProcess.Starting - The process is starting, but the program has not yet been invoked. - QProcess.Running - The process is running and is ready for reading and writing. - See also 
 - class ProcessChannel¶
- 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.- Constant - Description - QProcess.StandardOutput - The standard output (stdout) of the running process. - QProcess.StandardError - The standard error (stderr) of the running process. - See also 
 - class ProcessChannelMode¶
- This enum describes the process output channel modes of - QProcess. Pass one of these values to- setProcessChannelMode()to set the current read channel mode.- Constant - Description - QProcess.SeparateChannels - QProcessmanages 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.- QProcess.MergedChannels - QProcessmerges 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. For detached processes, the merged output of the running process is forwarded onto the main process.- QProcess.ForwardedChannels - QProcessforwards 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.- QProcess.ForwardedErrorChannel - QProcessmanages the standard output of the running process, but forwards its standard error onto the main process. This reflects the typical use of command line tools as filters, where the standard output is redirected to another process or a file, while standard error is printed to the console for diagnostic purposes. (This value was introduced in Qt 5.2.)- QProcess.ForwardedOutputChannel - Complementary to ForwardedErrorChannel. (This value was introduced in Qt 5.2.) - Note - Windows intentionally suppresses output from GUI-only applications to inherited consoles. This does not apply to output redirected to files or pipes. To forward the output of GUI-only applications on the console nonetheless, you must use SeparateChannels and do the forwarding yourself by reading the output and writing it to the appropriate output channels. - See also 
 - class InputChannelMode¶
- This enum describes the process input channel modes of - QProcess. Pass one of these values to- setInputChannelMode()to set the current write channel mode.- Constant - Description - QProcess.ManagedInputChannel - QProcessmanages the input of the running process. This is the default input channel mode of- QProcess.- QProcess.ForwardedInputChannel - QProcessforwards the input of the main process onto the running process. The child process reads its standard input from the same source as the main process. Note that the main process must not try to read its standard input while the child process is running.- See also 
 - class ExitStatus¶
- This enum describes the different exit statuses of - QProcess.- Constant - Description - QProcess.NormalExit - The process exited normally. - QProcess.CrashExit - The process crashed. - See also 
 - class UnixProcessFlag¶
- (inherits - enum.Flag) These flags can be used in the- flagsfield of- UnixProcessParameters.- Constant - Description - QProcess.UnixProcessFlag.CloseFileDescriptors - Close all file descriptors above the threshold defined by - lowestFileDescriptorToClose, preventing any currently open descriptor in the parent process from accidentally leaking to the child. The- stdin,- stdout, and- stderrfile descriptors are never closed.- QProcess.UnixProcessFlag.CreateNewSession - Starts a new process session, by calling - setsid(2). This allows the child process to outlive the session the current process is in. This is one of the steps that- startDetached()takes to allow the process to detach, and is also one of the steps to daemonize a process.- QProcess.UnixProcessFlag.DisconnectControllingTerminal - Requests that the process disconnect from its controlling terminal, if it has one. If it has none, nothing happens. Processes still connected to a controlling terminal may get a Hang Up ( - SIGHUP) signal if the terminal closes, or one of the other terminal-control signals (- SIGTSTP,- SIGTTIN,- SIGTTOU). Note that on some operating systems, a process may only disconnect from the controlling terminal if it is the session leader, meaning the- CreateNewSessionflag may be required. Like it, this is one of the steps to daemonize a process.- QProcess.UnixProcessFlag.IgnoreSigPipe - Always sets the - SIGPIPEsignal to ignored (- SIG_IGN), even if the- ResetSignalHandlersflag was set. By default, if the child attempts to write to its standard output or standard error after the respective channel was closed with- closeReadChannel(), it would get the- SIGPIPEsignal and terminate immediately; with this flag, the write operation fails without a signal and the child may continue executing.- QProcess.UnixProcessFlag.ResetIds - Drops any retained, effective user or group ID the current process may still have (see - setuid(2)and- setgid(2), plus QCoreApplication::setSetuidAllowed()). This is useful if the current process was setuid or setgid and does not wish the child process to retain the elevated privileges.- QProcess.UnixProcessFlag.ResetSignalHandlers - Resets all Unix signal handlers back to their default state (that is, pass - SIG_DFLto- signal(2)). This flag is useful to ensure any ignored (- SIG_IGN) signal does not affect the child’s behavior.- QProcess.UnixProcessFlag.UseVFork - Requests that - QProcessuse- vfork(2)to start the child process. Use this flag to indicate that the callback function set with- setChildProcessModifier()is safe to execute in the child side of a- vfork(2); that is, the callback does not modify any non-local variables (directly or through any function it calls), nor attempts to communicate with the parent process. It is implementation-defined if- QProcesswill actually use- vfork(2)and if- vfork(2)is different from standard- fork(2).- Added in version 6.6. 
 - Constructs a - QProcessobject with the given- parent.- arguments()¶
- Return type:
- list of strings 
 
 - Returns the command line arguments the process was last started with. - See also - closeReadChannel(channel)¶
- Parameters:
- channel – - ProcessChannel
 
 - Closes the read channel - channel. After calling this function,- QProcesswill 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()¶
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Schedules the write channel of - QProcessto 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:- more = QProcess() 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 - environment()¶
- Return type:
- list of strings 
 
 - Returns the environment that - QProcesswill pass to its child process, or an empty- QStringListif no environment has been set using- setEnvironment(). If no environment has been set, the environment of the calling process will be used.- error()¶
- Return type:
 
 - Returns the type of error that occurred last. - See also - errorOccurred(error)¶
- Parameters:
- error – - ProcessError
 
 - This signal is emitted when an error occurs with the process. The specified - errordescribes the type of error that occurred.- static execute(program[, arguments={}])¶
- Parameters:
- program – str 
- arguments – list of strings 
 
- Return type:
- int 
 
 - Starts the program - programwith the arguments- argumentsin 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. - Argument handling is identical to the respective - start()overload.- If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process’ exit code is returned. - See also - exitCode()¶
- Return type:
- int 
 
 - Returns the exit code of the last process that finished. - This value is not valid unless - exitStatus()returns- NormalExit.- exitStatus()¶
- Return type:
 
 - 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 - NormalExitunless the exit code is less than 0.- failChildProcessModifier(description[, error=0])¶
- Parameters:
- description – str 
- error – int 
 
 
 - This functions can be used inside the modifier set with - setChildProcessModifier()to indicate an error condition was encountered. When the modifier calls these functions,- QProcesswill emit- errorOccurred()with code- FailedToStartin the parent process. The- descriptioncan be used to include some information in- errorString()to help diagnose the problem, usually the name of the call that failed, similar to the C Library function- perror(). Additionally, the- errorparameter can be an- <errno.h>error code whose text form will also be included.- For example, a child modifier could prepare an extra file descriptor for the child process this way: - process.setChildProcessModifier([fd, &process]() { if (dup2(fd, TargetFileDescriptor) < 0) process.failChildProcessModifier(errno, "aux comm channel"); }); process.start(); - Where - fdis a file descriptor currently open in the parent process. If the- dup2()system call resulted in an- EBADFcondition, the process- errorString()could be “Child process modifier reported error: aux comm channel: Bad file descriptor”.- This function does not return to the caller. Using it anywhere except in the child modifier and with the correct - QProcessobject is undefined behavior.- Note - The implementation imposes a length limit to the - descriptionparameter to about 500 characters. This does not include the text from the- errorcode.- See also - setChildProcessModifier()- setUnixProcessParameters()- finished(exitCode[, exitStatus=QProcess.ExitStatus.NormalExit])¶
- Parameters:
- exitCode – int 
- exitStatus – - ExitStatus
 
 
 - This signal is emitted when the process finishes. - exitCodeis the exit code of the process (only valid for normal exits), and- exitStatusis the exit status. After the process has finished, the buffers in- QProcessare still intact. You can still read any data that the process may have written before it finished.- See also - inputChannelMode()¶
- Return type:
 
 - Returns the channel mode of the - QProcessstandard input channel.- See also - kill()¶
 - Kills the current process, causing it to exit immediately. - On Windows, kill() uses TerminateProcess, and on Unix and macOS, the SIGKILL signal is sent to the process. - See also - static nullDevice()¶
- Return type:
- str 
 
 - The null device of the operating system. - The returned file path uses native directory separators. - processChannelMode()¶
- Return type:
 
 - Returns the channel mode of the - QProcessstandard output and standard error channels.- processEnvironment()¶
- Return type:
 
 - Returns the environment that - QProcesswill pass to its child process. If no environment has been set using- setProcessEnvironment(), this method returns an object indicating the environment will be inherited from the parent.- See also - setProcessEnvironment()- inheritsFromParent()- Environment variables- processId()¶
- Return type:
- int 
 
 - Returns the native process identifier for the running process, if available. If no process is currently running, - 0is returned.- program()¶
- Return type:
- str 
 
 - Returns the program the process was last started with. - See also - readAllStandardError()¶
- Return type:
 
 - Regardless of the current read channel, this function returns all data available from the standard error of the process as a - QByteArray.- readAllStandardOutput()¶
- Return type:
 
 - Regardless of the current read channel, this function returns all data available from the standard output of the process as a - QByteArray.- readChannel()¶
- Return type:
 
 - Returns the current read channel of the - QProcess.- See also - readyReadStandardError()¶
 - 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 - readyReadStandardOutput()¶
 - 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 - setArguments(arguments)¶
- Parameters:
- arguments – list of strings 
 
 - Set the - argumentsto pass to the called program when starting the process. This function must be called before- start().- See also - setEnvironment(environment)¶
- Parameters:
- environment – list of strings 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the environment that - QProcesswill pass to the child process. The parameter- environmentis a list of key=value pairs.- For example, the following code adds the environment variable - TMPDIR:- process = QProcess() env = QProcess.systemEnvironment() env << "TMPDIR=C:\\MyApp\\temp" # Add an environment variable process.setEnvironment(env) process.start("myapp") - Note - This function is less efficient than the - setProcessEnvironment()function.- setInputChannelMode(mode)¶
- Parameters:
- mode – - InputChannelMode
 
 - Sets the channel mode of the - QProcessstandard input channel to the- modespecified. This mode will be used the next time- start()is called.- See also - setProcessChannelMode(mode)¶
- Parameters:
- mode – - ProcessChannelMode
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the channel mode of the - QProcessstandard output and standard error channels to the- modespecified. This mode will be used the next time- start()is called. For example:- builder = QProcess() builder.setProcessChannelMode(QProcess.MergedChannels) builder.start("make", QStringList() << "-j2") if not builder.waitForFinished(): print("Make failed:", builder.errorString()) else: print("Make output:", builder.readAll()) - setProcessEnvironment(environment)¶
- Parameters:
- environment – - QProcessEnvironment
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the - environmentthat- QProcesswill pass to the child process.- For example, the following code adds the environment variable - TMPDIR:- process = QProcess() env = QProcessEnvironment.systemEnvironment() env.insert("TMPDIR", "C:\\MyApp\\temp") # Add an environment variable process.setProcessEnvironment(env) process.start("myapp") - Note how, on Windows, environment variable names are case-insensitive. - See also - processEnvironment()- systemEnvironment()- Environment variables- setProcessState(state)¶
- Parameters:
- state – - ProcessState
 
 - Sets the current state of the - QProcessto the- statespecified.- See also - setProgram(program)¶
- Parameters:
- program – str 
 
 - Set the - programto use when starting the process. This function must be called before- start().- If - programis an absolute path, it specifies the exact executable that will be launched. Relative paths will be resolved in a platform-specific manner, which includes searching the- PATHenvironment variable (see- Finding the Executablefor details).- See also - setReadChannel(channel)¶
- Parameters:
- channel – - ProcessChannel
 
 - Sets the current read channel of the - QProcessto the given- channel. The current input channel is used by the functions- read(),- readAll(),- readLine(), and- getChar(). It also determines which channel triggers- QProcessto emit- readyRead().- See also - setStandardErrorFile(fileName[, mode=QIODeviceBase.OpenModeFlag.Truncate])¶
- Parameters:
- fileName – str 
- mode – Combination of - OpenModeFlag
 
 
 - 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- modeis 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- MergedChannels, this function has no effect.- setStandardInputFile(fileName)¶
- Parameters:
- fileName – str 
 
 - Redirects the process’ standard input to the file indicated by - fileName. When an input redirection is in place, the- QProcessobject will be in read-only mode (calling- write()will result in error).- To make the process read EOF right away, pass - nullDevice()here. This is cleaner than using- closeWriteChannel()before writing any data, because it can be set up prior to starting the process.- If the file - fileNamedoes 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(fileName[, mode=QIODeviceBase.OpenModeFlag.Truncate])¶
- Parameters:
- fileName – str 
- mode – Combination of - OpenModeFlag
 
 
 - 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().- To discard all standard output from the process, pass - nullDevice()here. This is more efficient than simply never reading the standard output, as no- QProcessbuffers are filled.- If the file - fileNamedoesn’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 - modeis- Truncate, the file will be truncated. Otherwise (if- modeis- Append), the file will be appended to.- Calling setStandardOutputFile() after the process has started has no effect. - If - fileNameis an empty string, it stops redirecting the standard output. This is useful for restoring the standard output after redirection.- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Pipes the standard output stream of this process to the - destinationprocess’ standard input.- The following shell command: - command1 | command2 - Can be accomplished with - QProcesswith the following code:- process1 = QProcess() process2 = QProcess() process1.setStandardOutputProcess(process2) process1.start("command1") process2.start("command2") - setUnixProcessParameters(flagsOnly)¶
- Parameters:
- flagsOnly – Combination of - UnixProcessFlag
 
 - This is an overloaded function. - Sets the extra settings for the child process on Unix systems to - flagsOnly. This is the same as the overload with just the- flagsfield set.- Note - This function is only available on Unix platforms. - See also - unixProcessParameters()- setChildProcessModifier()- setUnixProcessParameters(params)
- Parameters:
- params – - UnixProcessParameters
 
 - Sets the extra settings and parameters for the child process on Unix systems to be - params. This function can be used to ask- QProcessto modify the child process before launching the target executable.- This function can be used to change certain properties of the child process, such as closing all extraneous file descriptors, changing the nice level of the child, or disconnecting from the controlling TTY. For more fine-grained control of the child process or to modify it in other ways, use the - setChildProcessModifier()function. If both a child process modifier and Unix process parameters are set, the modifier is run before these parameters are applied.- Note - This function is only available on Unix platforms. - See also - unixProcessParameters()- setChildProcessModifier()- setWorkingDirectory(dir)¶
- Parameters:
- dir – str 
 
 - Sets the working directory to - dir.- QProcesswill start the process in this directory. The default behavior is to start the process in the working directory of the calling process.- See also - static splitCommand(command)¶
- Parameters:
- command – str 
- Return type:
- list of strings 
 
 - Splits the string - commandinto a list of tokens, and returns the list.- Tokens with spaces can be surrounded by double quotes; three consecutive double quotes represent the quote character itself. - start([mode=QIODeviceBase.OpenModeFlag.ReadWrite])¶
- Parameters:
- mode – Combination of - OpenModeFlag
 
 - This is an overloaded function. - Starts the program set by - setProgram()with arguments set by- setArguments(). The OpenMode is set to- mode.- See also - open()- setProgram()- setArguments()- start(program[, arguments={}[, mode=QIODeviceBase.OpenModeFlag.ReadWrite]])
- Parameters:
- program – str 
- arguments – list of strings 
- mode – Combination of - OpenModeFlag
 
 
 - Starts the given - programin a new process, passing the command line arguments in- arguments. See- setProgram()for information about how- QProcesssearches for the executable to be run. The OpenMode is set to- mode. No further splitting of the arguments is performed.- The - QProcessobject will immediately enter the Starting state. If the process starts successfully,- QProcesswill emit- started(); otherwise,- errorOccurred()will be emitted. Do note that on platforms that are able to start child processes synchronously (notably Windows), those signals will be emitted before this function returns and this- QProcessobject will transition to either- Runningor- NotRunningstate, respectively. On others paltforms, the- started()and- errorOccurred()signals will be delayed.- Call - waitForStarted()to make sure the process has started (or has failed to start) and those signals have been emitted. It is safe to call that function even if the process starting state is already known, though the signal will not be emitted again.- Windows: The arguments are quoted and joined into a command line that is compatible with the - CommandLineToArgvW()Windows function. For programs that have different command line quoting requirements, you need to use- setNativeArguments(). One notable program that does not follow the- CommandLineToArgvW()rules is cmd.exe and, by consequence, all batch scripts.- If the - QProcessobject is already running a process, a warning may be printed at the console, and the existing process will continue running unaffected.- Note - Success at starting the child process only implies the operating system has successfully created the process and assigned the resources every process has, such as its process ID. The child process may crash or otherwise fail very early and thus not produce its expected output. On most operating systems, this may include dynamic linking errors. - See also - processId()- started()- waitForStarted()- setNativeArguments()- startCommand(command[, mode=QIODeviceBase.OpenModeFlag.ReadWrite])¶
- Parameters:
- command – str 
- mode – Combination of - OpenModeFlag
 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Starts the command - commandin a new process. The OpenMode is set to- mode.- commandis a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces. For example:- process = QProcess() process.startCommand("del /s *.txt") # same as process.start("del", QStringList() << "/s" << "*.txt") ... - Arguments containing spaces must be quoted to be correctly supplied to the new process. For example: - process = QProcess() process.startCommand("dir \"My Documents\"") - Literal quotes in the - commandstring are represented by triple quotes. For example:- process = QProcess() process.startCommand("dir \"Epic 12\"\"\" Singles\"") - After the - commandstring has been split and unquoted, this function behaves like- start().- On operating systems where the system API for passing command line arguments to a subprocess natively uses a single string (Windows), one can conceive command lines which cannot be passed via - QProcess‘s portable list-based API. In these rare cases you need to use- setProgram()and- setNativeArguments()instead of this function.- See also - startDetached([pid=None])¶
- Parameters:
- pid – - qint64
- Return type:
- bool 
 
 - Starts the program set by - setProgram()with arguments set by- setArguments()in a new process, and detaches from it. Returns- trueon success; otherwise returns- false. If the calling process exits, the detached process will continue to run unaffected.- Unix: The started process will run in its own session and act like a daemon. - The process will be started in the directory set by - setWorkingDirectory(). If- workingDirectory()is empty, the working directory is inherited from the calling process.- If the function is successful then *``pid`` is set to the process identifier of the started process; otherwise, it’s set to -1. Note that the child process may exit and the PID may become invalid without notice. Furthermore, after the child process exits, the same PID may be recycled and used by a completely different process. User code should be careful when using this variable, especially if one intends to forcibly terminate the process by operating system means. - Only the following property setters are supported by startDetached(): 
- setCreateProcessArgumentsModifier()
- setNativeArguments()
 - All other properties of the - QProcessobject are ignored.- Note - The called process inherits the console window of the calling process. To suppress console output, redirect standard/error output to - nullDevice().- See also - start()- startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)- static startDetached(program[, arguments={}[, workingDirectory=""]])
- Parameters:
- program – str 
- arguments – list of strings 
- workingDirectory – str 
 
- Return type:
- (retval, pid) 
 
 - This function overloads - startDetached().- Starts the program - programwith the arguments- argumentsin a new process, and detaches from it. Returns- trueon success; otherwise returns- false. If the calling process exits, the detached process will continue to run unaffected.- Argument handling is identical to the respective - start()overload.- The process will be started in the directory - workingDirectory. If- workingDirectoryis empty, the working directory is inherited from the calling process.- If the function is successful then *``pid`` is set to the process identifier of the started process. - See also - started()¶
 - This signal is emitted by - QProcesswhen the process has started, and- state()returns- Running.- state()¶
- Return type:
 
 - Returns the current state of the process. - See also - stateChanged(state)¶
- Parameters:
- state – - ProcessState
 
 - This signal is emitted whenever the state of - QProcesschanges. The- newStateargument is the state- QProcesschanged to.- static systemEnvironment()¶
- Return type:
- list of strings 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the environment of the calling process as a list of key=value pairs. Example: - 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 - setenvor- putenvhave 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 - systemEnvironment()- 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 top-level windows of the process and then to the main thread of the process itself. On Unix and macOS the - SIGTERMsignal 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().- See also - unixProcessParameters()¶
- Return type:
 
 - Returns the - UnixProcessParametersobject describing extra flags and settings that will be applied to the child process on Unix systems. The default settings correspond to a default-constructed- UnixProcessParameters.- Note - This function is only available on Unix platforms. - See also - setUnixProcessParameters()- childProcessModifier()- waitForFinished([msecs=30000])¶
- Parameters:
- msecs – int 
- Return type:
- bool 
 
 - Blocks until the process has finished and the - finished()signal has been emitted, or until- msecsmilliseconds have passed.- Returns - trueif the process finished; otherwise returns- false(if the operation timed out, if an error occurred, or if this- QProcessis 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()- waitForBytesWritten()- waitForStarted([msecs=30000])¶
- Parameters:
- msecs – int 
- Return type:
- bool 
 
 - Blocks until the process has started and the - started()signal has been emitted, or until- msecsmilliseconds have passed.- Returns - trueif the process was started successfully; otherwise returns- false(if the operation timed out or if an error occurred). If the process had already started successfully before this function, it returns immediately.- 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()- waitForFinished()- workingDirectory()¶
- Return type:
- str 
 
 - If - QProcesshas been assigned a working directory, this function returns the working directory that the- QProcesswill enter before the program has started. Otherwise, (i.e., no directory has been assigned,) an empty string is returned, and- QProcesswill use the application’s current working directory instead.- See also - class UnixProcessParameters¶
- Added in version 6.6. - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- PySide6.QtCore.QProcess.UnixProcessParameters.flags¶
 - PySide6.QtCore.QProcess.UnixProcessParameters.lowestFileDescriptorToClose¶
 - PySide6.QtCore.QProcess.UnixProcessParameters._reserved¶