def
arguments
()
def
closeReadChannel
(channel)
def
closeWriteChannel
()
def
environment
()
def
error
()
def
exitCode
()
def
exitStatus
()
def
inputChannelMode
()
def
processChannelMode
()
def
processEnvironment
()
def
processId
()
def
program
()
def
readAllStandardError
()
def
readAllStandardOutput
()
def
readChannel
()
def
setArguments
(arguments)
def
setEnvironment
(environment)
def
setInputChannelMode
(mode)
def
setProcessChannelMode
(mode)
def
setProcessEnvironment
(environment)
def
setProcessState
(state)
def
setProgram
(program)
def
setReadChannel
(channel)
def
setStandardErrorFile
(fileName[, mode=QIODevice.Truncate])
def
setStandardInputFile
(fileName)
def
setStandardOutputFile
(fileName[, mode=QIODevice.Truncate])
def
setStandardOutputProcess
(destination)
def
setWorkingDirectory
(dir)
def
start
([mode=QIODevice.ReadWrite])
def
start
(command[, mode=QIODevice.ReadWrite])
def
start
(program, arguments[, mode=QIODevice.ReadWrite])
def
startDetached
([pid=None])
def
state
()
def
waitForFinished
([msecs=30000])
def
waitForStarted
([msecs=30000])
def
workingDirectory
()
def
setupChildProcess
()
def
error
(error)
def
errorOccurred
(error)
def
finished
(exitCode)
def
finished
(exitCode, exitStatus)
def
execute
(command)
def
execute
(program, arguments)
def
nullDevice
()
def
startDetached
(command)
def
startDetached
(program, arguments)
def
startDetached
(program, arguments, workingDirectory)
def
systemEnvironment
()
要启动进程,把希望运行的程序名称和命令行自变量作为自变量传递给
start(). Arguments are supplied as individual strings in aQStringList.另外,可以设置要运行的程序采用
setProgram()andsetArguments(), and then callstart()oropen().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:
QObject *parent; ... QString program = "./path/to/Qt/examples/widgets/analogclock"; QStringList arguments; arguments << "-style" << "fusion"; QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments);
QProcessthen enters theStartingstate, and when the program has started,QProcessenters the运行状态并发射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 usingQTcpSocket. You can then write to the process’s standard input by callingwrite(), and read the standard output by callingread(),readLine(),和getChar(). Because it inheritsQIODevice,QProcesscan also be used as an input source forQXmlReader,或对于生成要上传的数据使用QNetworkAccessManager.When the process exits,
QProcessreenters theNotRunning状态 (初始状态),并发射finished().
finished()signal provides the exit code and exit status of the process as arguments, and you can also callexitCode()to obtain the exit code of the last process that finished, andexitStatus()to obtain its exit status. If an error occurs at any point in time,QProcess将发射errorOccurred()signal. You can also callerror()to find the type of error that occurred last, andstate()to find the current process state.注意
QProcessis not supported on VxWorks, iOS, tvOS, watchOS, or the Universal Windows Platform.
进程有 2 个预定义输出通道:标准输出通道 (
stdout) 提供常规控制台输出,和标准错误通道 (stderr) 通常提供由进程打印的错误。这些通道表示 2 个单独数据流。可以在它们之间切换通过调用setReadChannel().QProcess发射readyRead()when data is available on the current read channel. It also emitsreadyReadStandardOutput()when new standard output data is available, and when new standard error data is available,readyReadStandardError()is emitted. Instead of callingread(),readLine(),或getChar(), you can explicitly read all data from either of the two channels by callingreadAllStandardOutput()orreadAllStandardError().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 toQProcess‘s write channels. This is because what we read usingQProcessis 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. CallsetProcessChannelMode()withMergedChannels在开始激活此特征的进程之前。还有将正运行进程输出转发到调用主进程的选项,通过传递ForwardedChannels作为自变量。只转发某个输出通道是可能的 - 通常会使用ForwardedErrorChannel,但ForwardedOutputChannel也存在。注意,在 GUI 应用程序中使用通道转发通常是个坏主意 - 应该以图形呈现错误取而代之。某些进程需要特殊环境设置才能运转。可以为进程设置环境变量通过调用
setProcessEnvironment(). To set a working directory, callsetWorkingDirectory(). 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-qwindowgeometry命令行选项;X11 应用程序一般接受-geometry命令行选项。注意
On QNX, setting the working directory may cause all application threads, with the exception of the
QProcesscaller thread, to temporarily freeze during the spawning process, owing to a limitation in the operating system.
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.从主线程调用这些函数 (线程调用
exec()) may cause your user interface to freeze.以下范例运行
gzipto 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();
某些 Windows 命令 (例如,
dir) are not provided by separate applications, but by the command interpreter itself. If you attempt to useQProcessto execute these commands directly, it won’t work. One possible solution is to execute the command interpreter itself (cmd.exe在某些 Windows 系统),和要求解释器执行期望命令。另请参阅
PySide2.QtCore.QProcess.
ProcessError
¶
此枚举描述错误的不同类型,报告通过
QProcess
.
|
常量 |
描述 |
|---|---|
|
QProcess.FailedToStart |
The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program. |
|
QProcess.Crashed |
进程有时崩溃在成功启动后。 |
|
QProcess.Timedout |
The last waitFor…() function timed out. The state of
|
|
QProcess.WriteError |
发生错误当试图写入进程时。例如,进程可能未运行,或它可能已关闭其输入通道。 |
|
QProcess.ReadError |
发生错误当试图从进程读取时。例如,进程可能未运行。 |
|
QProcess.UnknownError |
发生未知错误。这是默认返回值为
|
另请参阅
PySide2.QtCore.QProcess.
ProcessState
¶
此枚举描述不同状态为
QProcess
.
|
常量 |
描述 |
|---|---|
|
QProcess.NotRunning |
进程未运行。 |
|
QProcess.Starting |
进程正在启动,但尚未援引程序。 |
|
QProcess.Running |
进程正在运行且读写就绪。 |
另请参阅
PySide2.QtCore.QProcess.
ProcessChannel
¶
此枚举描述正运行进程所使用的进程通道。传递这些值之一给
setReadChannel()
to set the current read channel of
QProcess
.
|
常量 |
描述 |
|---|---|
|
QProcess.StandardOutput |
正运行进程的 stdout (标准输出)。 |
|
QProcess.StandardError |
正运行进程的 stderr (标准错误)。 |
另请参阅
PySide2.QtCore.QProcess.
ProcessChannelMode
¶
此枚举描述进程的输出通道模式为
QProcess
。将这些值之一传递给
setProcessChannelMode()
to set the current read channel mode.
|
常量 |
描述 |
|---|---|
|
QProcess.SeparateChannels |
|
|
QProcess.MergedChannels |
|
|
QProcess.ForwardedChannels |
|
|
QProcess.ForwardedErrorChannel |
|
|
QProcess.ForwardedOutputChannel |
Complementary to . (This value was introduced in Qt 5.2.) |
注意
Windows 有意抑制从仅 GUI 应用程序输出到继承控制台。 这 not apply to output redirected to files or pipes. To forward the output of GUI-only applications on the console nonetheless, you must use and do the forwarding yourself by reading the output and writing it to the appropriate output channels.
PySide2.QtCore.QProcess.
InputChannelMode
¶
此枚举描述进程输入通道模式为
QProcess
。将这些值之一传递给
setInputChannelMode()
to set the current write channel mode.
|
常量 |
描述 |
|---|---|
|
QProcess.ManagedInputChannel |
|
|
QProcess.ForwardedInputChannel |
|
PySide2.QtCore.QProcess.
ExitStatus
¶
此枚举描述不同退出状态为
QProcess
.
|
常量 |
描述 |
|---|---|
|
QProcess.NormalExit |
进程正常退出。 |
|
QProcess.CrashExit |
进程崩溃。 |
另请参阅
PySide2.QtCore.QProcess.
arguments
(
)
¶
字符串列表
返回上次启动进程采用的命令行自变量。
另请参阅
PySide2.QtCore.QProcess.
closeReadChannel
(
channel
)
¶
channel
–
ProcessChannel
关闭读取通道
channel
。在调用此函数后,
QProcess
将不再接收通道数据。任何已收到的数据仍可用于读取。
调用此函数以节省内存,若对进程的输出不感兴趣。
PySide2.QtCore.QProcess.
closeWriteChannel
(
)
¶
调度写入通道对于
QProcess
要被关闭。一旦所有数据被写入进程,通道就将关闭。在调用此函数后,任何写入进程的试图都将失败。
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
写入通道被隐式打开当
start()
被调用。
另请参阅
PySide2.QtCore.QProcess.
environment
(
)
¶
字符串列表
返回环境
QProcess
will pass to its child process, or an empty
QStringList
if no environment has been set using
setEnvironment()
. If no environment has been set, the environment of the calling process will be used.
PySide2.QtCore.QProcess.
error
(
)
¶
返回最后发生的错误类型。
另请参阅
PySide2.QtCore.QProcess.
error
(
error
)
¶
error
–
ProcessError
注意
此函数被弃用。
PySide2.QtCore.QProcess.
errorOccurred
(
error
)
¶
error
–
ProcessError
PySide2.QtCore.QProcess.
execute
(
command
)
¶
command – unicode
int
注意
此函数被弃用。
这是重载函数。
启动程序
command
in a new process, waits for it to finish, and then returns the exit code.
自变量处理分别等同
start()
overload.
之后
command
string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.
另请参阅
start()
splitCommand()
PySide2.QtCore.QProcess.
execute
(
program
,
arguments
)
¶
program – unicode
arguments – 字符串列表
int
启动程序
program
采用自变量
arguments
在新进程中,等待它完成,然后返回进程的退出代码。新进程写入控制台的任何数据会被转发给调用进程。
环境和工作目录继承自调用进程。
自变量处理分别等同
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.
另请参阅
PySide2.QtCore.QProcess.
exitCode
(
)
¶
int
返回最后完成进程的退出代码。
此值无效除非
exitStatus()
返回
NormalExit
.
PySide2.QtCore.QProcess.
exitStatus
(
)
¶
返回最后完成的进程退出状态。
在 Windows,若进程被另一应用程序的 TerminateProcess() 所终止,此函数仍会返回
NormalExit
除非退出代码小于 0。
PySide2.QtCore.QProcess.
finished
(
exitCode
,
exitStatus
)
¶
exitCode
–
int
exitStatus
–
ExitStatus
PySide2.QtCore.QProcess.
finished
(
exitCode
)
¶
exitCode
–
int
注意
此函数被弃用。
PySide2.QtCore.QProcess.
inputChannelMode
(
)
¶
返回通道模式对于
QProcess
标准输入通道。
另请参阅
setInputChannelMode()
InputChannelMode
PySide2.QtCore.QProcess.
kill
(
)
¶
杀除当前进程,导致它立即退出。
On Windows, uses TerminateProcess, and on Unix and macOS, the SIGKILL signal is sent to the process.
另请参阅
PySide2.QtCore.QProcess.
nullDevice
(
)
¶
unicode
操作系统的 null 设备。
返回的文件路径使用本机目录分隔符。
PySide2.QtCore.QProcess.
processChannelMode
(
)
¶
返回通道模式对于
QProcess
标准输出和标准错误通道。
另请参阅
setProcessChannelMode()
ProcessChannelMode
setReadChannel()
PySide2.QtCore.QProcess.
processEnvironment
(
)
¶
返回环境
QProcess
will pass to its child 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.
PySide2.QtCore.QProcess.
processId
(
)
¶
qint64
返回正在运行进程的本机进程标识符,若可用。若目前没有进程正在运行,
0
被返回。
PySide2.QtCore.QProcess.
program
(
)
¶
unicode
返回进程最后一次启动时采用的程序。
另请参阅
PySide2.QtCore.QProcess.
readAllStandardError
(
)
¶
不管当前读取通道,此函数从进程标准错误返回所有可用数据按
QByteArray
.
另请参阅
readyReadStandardError()
readAllStandardOutput()
readChannel()
setReadChannel()
PySide2.QtCore.QProcess.
readAllStandardOutput
(
)
¶
不管当前读取通道,此函数从进程标准输出返回所有可用数据按
QByteArray
.
另请参阅
readyReadStandardOutput()
readAllStandardError()
readChannel()
setReadChannel()
PySide2.QtCore.QProcess.
setArguments
(
arguments
)
¶
arguments – 字符串列表
设置
arguments
以传递给被调用程序当启动进程时。必须调用此函数先于
start()
.
PySide2.QtCore.QProcess.
setEnvironment
(
environment
)
¶
environment – 字符串列表
Sets the environment that
QProcess
will pass to the child process. The parameter
environment
is a list of key=value pairs.
例如,以下代码添加环境变量
TMPDIR
:
QProcess process;
QStringList env = QProcess::systemEnvironment();
env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
process.setEnvironment(env);
process.start("myapp");
注意
This function is less efficient than the
setProcessEnvironment()
函数。
PySide2.QtCore.QProcess.
setInputChannelMode
(
mode
)
¶
mode
–
InputChannelMode
设置通道模式为
QProcess
标准输入通道到
mode
指定。会使用此模式当下次
start()
被调用。
另请参阅
inputChannelMode()
InputChannelMode
PySide2.QtCore.QProcess.
setProcessChannelMode
(
mode
)
¶
mode
–
ProcessChannelMode
设置通道模式为
QProcess
标准输出和标准错误通道到
mode
指定。会使用此模式当下次
start()
is called. For example:
builder = QProcess()
builder.setProcessChannelMode(QProcess.MergedChannels)
builder.start("make", ["-j2"])
import sys
if not builder.waitForFinished():
sys.stderr.write("Make failed:" + builder.errorString())
else
sys.stderr.write("Make output:" + builder.readAll())
另请参阅
processChannelMode()
ProcessChannelMode
setReadChannel()
PySide2.QtCore.QProcess.
setProcessEnvironment
(
environment
)
¶
environment
–
QProcessEnvironment
设置
environment
that
QProcess
将传递给子级进程。
例如,以下代码添加环境变量
TMPDIR
:
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
process.setProcessEnvironment(env);
process.start("myapp");
注意:在 Windows,环境变量名称是不区分大小写的。
PySide2.QtCore.QProcess.
setProcessState
(
state
)
¶
state
–
ProcessState
设置当前状态为
QProcess
到
state
指定。
另请参阅
PySide2.QtCore.QProcess.
setProgram
(
program
)
¶
program – unicode
设置
program
to use when starting the process. This function must be called before
start()
.
PySide2.QtCore.QProcess.
setReadChannel
(
channel
)
¶
channel
–
ProcessChannel
设置当前读取通道为
QProcess
到给定
channel
。当前输入通道用于函数
read()
,
readAll()
,
readLine()
,和
getChar()
. It also determines which channel triggers
QProcess
以发射
readyRead()
.
另请参阅
PySide2.QtCore.QProcess.
setStandardErrorFile
(
fileName
[
,
mode=QIODevice.Truncate
]
)
¶
fileName – unicode
mode
–
OpenMode
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.
见
setStandardOutputFile()
for more information on how the file is opened.
Note: if
setProcessChannelMode()
was called with an argument of
MergedChannels
,此函数不起作用。
PySide2.QtCore.QProcess.
setStandardInputFile
(
fileName
)
¶
fileName – unicode
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).
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
fileName
does not exist at the moment
start()
is called or is not readable, starting the process will fail.
Calling after the process has started has no effect.
PySide2.QtCore.QProcess.
setStandardOutputFile
(
fileName
[
,
mode=QIODevice.Truncate
]
)
¶
fileName – unicode
mode
–
OpenMode
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
QProcess
buffers are filled.
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
Truncate
, the file will be truncated. Otherwise (if
mode
is
追加
), the file will be appended to.
Calling after the process has started has no effect.
PySide2.QtCore.QProcess.
setStandardOutputProcess
(
destination
)
¶
destination
–
QProcess
将此进程的标准输出流管道到
destination
process’ standard input.
以下 Shell 命令:
command1 | command2
可以完成采用
QProcess
通过以下代码:
process1 = QProcess()
process2 = QProcess()
process1.setStandardOutputProcess(process2)
process1.start("command1")
process2.start("command2")
PySide2.QtCore.QProcess.
setWorkingDirectory
(
dir
)
¶
dir – unicode
把工作目录设为
dir
.
QProcess
将在此目录下启动进程。默认行为是在调用进程的工作目录下启动进程。
注意
在 QNX,这可能导致所有应用程序线程被临时冻结。
PySide2.QtCore.QProcess.
setupChildProcess
(
)
¶
This function is called in the child process context just before the program is executed on Unix or macOS (i.e., after
fork()
, but before
execve()
). Reimplement this function to do last minute initialization of the child process. Example:
class SandboxProcess(QProcess):
def setupChildProcess(self)
# Drop all privileges in the child process, and enter
# a chroot jail.
os.setgroups(0, 0)
os.chroot("/etc/safe")
os.chdir("/")
os.setgid(safeGid)
os.setuid(safeUid)
os.umask(0)
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().
警告
此函数被调用由
QProcess
on Unix and macOS only. On Windows and QNX, it is not called.
PySide2.QtCore.QProcess.
start
(
[
mode=QIODevice.ReadWrite
]
)
¶
mode
–
OpenMode
这是重载函数。
启动程序设置通过
setProgram()
with arguments set by
setArguments()
。
OpenMode
is set to
mode
.
另请参阅
open()
setProgram()
setArguments()
PySide2.QtCore.QProcess.
start
(
command
[
,
mode=QIODevice.ReadWrite
]
)
¶
command – unicode
mode
–
OpenMode
注意
此函数被弃用。
这是重载函数。
启动命令
command
in a new process. The
OpenMode
is set to
mode
.
command
是包含程序名称及其自变量的单文本字符串。自变量由一个或多个空格分隔。例如:
process = QProcess()
process.start("del /s *.txt")
# same as process.start("del", ["/s", "*.txt"])
...
必须引用包含空格的自变量才能被正确提供给新进程。例如:
process = QProcess()
process.start("dir \"My Documents\"")
文字引号在
command
字符串由 3 引号表示。例如:
process = QProcess()
process.start("dir \"\"\"My Documents\"\"\"")
之后
command
string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.
You can disable this overload by defining
QT_NO_PROCESS_COMBINED_ARGUMENT_START
when you compile your applications. This can be useful if you want to ensure that you are not splitting arguments unintentionally, for example. In virtually all cases, using the other overload is the preferred method.
在将命令行自变量传递给子进程的本机系统 API 使用单字符串的 Windows 操作系统,可以设想无法传递命令行凭借
QProcess
‘s portable list-based API. In these rare cases you need to use
setProgram()
and
setNativeArguments()
instead of this function.
另请参阅
splitCommand()
PySide2.QtCore.QProcess.
start
(
program
,
arguments
[
,
mode=QIODevice.ReadWrite
]
)
¶
program – unicode
arguments – 字符串列表
mode
–
OpenMode
启动给定
program
在新进程,传递的命令行自变量在
arguments
.
QProcess
对象将立即进入 Starting 状态。若进程成功启动,
QProcess
将发射
started()
;否则,
errorOccurred()
会被发射。
注意
进程是异步启动的,这意味着
started()
and
errorOccurred()
signals may be delayed. Call
waitForStarted()
to make sure the process has started (or has failed to start) and those signals have been emitted.
注意
不履行进一步的自变量分割。
Windows:
自变量加引号并被拼接到兼容命令行采用
CommandLineToArgvW()
Windows 函数。对于有不同命令行要求加引号的程序,需要使用
setNativeArguments()
. One notable program that does not follow the
CommandLineToArgvW()
规则是 cmd.exe,因此是所有批处理脚本。
OpenMode
is set to
mode
.
若
QProcess
对象已在运行进程,可能在控制台打印警告,且现有进程将不受影响地继续运行。
另请参阅
processId()
started()
waitForStarted()
setNativeArguments()
PySide2.QtCore.QProcess.
startDetached
(
command
)
¶
command – unicode
bool
注意
此函数被弃用。
PySide2.QtCore.QProcess.
startDetached
(
program
,
arguments
)
¶
program – unicode
arguments – 字符串列表
bool
PySide2.QtCore.QProcess.
startDetached
(
program
,
arguments
,
workingDirectory
)
¶
program – unicode
arguments – 字符串列表
workingDirectory – unicode
(retval, pid)
此函数重载
startDetached()
.
启动程序
program
采用自变量
arguments
在新进程中,并与之分离。返回
true
当成功时;否则返回
false
。若调用进程退出,分离进程将不受影响地继续运行。
自变量处理分别等同
start()
overload.
进程将被启动在目录
workingDirectory
。若
workingDirectory
为空,工作目录继承自调用进程。
If the function is successful then *``pid`` is set to the process identifier of the started process.
另请参阅
PySide2.QtCore.QProcess.
startDetached
(
[
pid=None
]
)
¶
pid
–
qint64
bool
启动程序设置通过
setProgram()
with arguments set by
setArguments()
在新进程中,并与之分离。返回
true
当成功时;否则返回
false
。若调用进程退出,分离进程将不受影响地继续运行。
Unix: 启动进程将在它自己的会话中运行,且行动像守护程序。
进程将在指定目录下启动设置通过
setWorkingDirectory()
。若
workingDirectory()
为空,工作目录继承自调用进程。
注意
在 QNX,这可能导致所有应用程序线程被临时冻结。
If the function is successful then *``pid`` is set to the process identifier of the started process. 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 :
setCreateProcessArgumentsModifier()
setNativeArguments()
所有其它特性对于
QProcess
对象被忽略。
注意
被调用进程继承调用进程的控制台窗口。要抑制控制台输出,请将标准/错误输出重定向到
nullDevice()
.
另请参阅
start()
startDetached(const
QString
&program,
const
QStringList
&arguments,
const
QString
&workingDirectory,
qint64
*pid)
startDetached(const
QString
&command)
PySide2.QtCore.QProcess.
systemEnvironment
(
)
¶
字符串列表
以 key=value 对列表形式返回调用进程的环境。范例:
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
or
putenv
有被调用。
不管怎样,注意,重复调用此函数将重新创建环境变量列表 (非通俗操作)。
注意
对于新代码,推荐使用
systemEnvironment()
PySide2.QtCore.QProcess.
terminate
(
)
¶
试图终止进程。
进程可能不会因调用此函数而退出 (它有机会提示用户是否有未保存的文件,等等)。
On Windows, 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
SIGTERM
信号被发送。
不运行事件循环的 Windows 控制台应用程序 (或其事件循环不处理 WM_CLOSE 消息),只可被终止通过调用
kill()
.
另请参阅
PySide2.QtCore.QProcess.
waitForFinished
(
[
msecs=30000
]
)
¶
msecs
–
int
bool
阻塞直到进程已完成且
finished()
signal has been emitted, or until
msecs
毫秒已过去。
返回
true
若进程已完成;否则返回
false
(若操作超时,若发生错误,或者若此
QProcess
已完成)。
可以在没有事件循环的情况下操作此函数。它很有用,当编写非 GUI 应用程序和在非 GUI 线程中履行 I/O 操作时。
警告
从主 GUI 线程调用此函数可能导致用户界面被冻结。
若 msecs 为 -1,此函数不会超时。
另请参阅
finished()
waitForStarted()
waitForReadyRead()
waitForBytesWritten()
PySide2.QtCore.QProcess.
waitForStarted
(
[
msecs=30000
]
)
¶
msecs
–
int
bool
阻塞直到进程启动且
started()
signal has been emitted, or until
msecs
毫秒已过去。
返回
true
若进程成功启动;否则返回
false
(若操作超时或发生错误)。
可以在没有事件循环的情况下操作此函数。它很有用,当编写非 GUI 应用程序和在非 GUI 线程中履行 I/O 操作时。
警告
从主 GUI 线程调用此函数可能导致用户界面被冻结。
若 msecs 为 -1,此函数不会超时。
注意
在某些 UNIX 操作系统,此函数可能返回 true 但进程可能稍后报告
FailedToStart
错误。
另请参阅
started()
waitForReadyRead()
waitForBytesWritten()
waitForFinished()