我似乎无法让QProcess
通过stdin
向cmd.exe
传递命令。我也尝试过其他命令行应用程序。在
下面是一些我用来调试的简单代码:
prog = "c:/windows/system32/cmd.exe"
arg = [""]
p = QtCore.QProcess()
retval = p.start(prog, arg)
print retval
print p.environment()
print p.error()
p.waitForStarted()
print("Started")
p.write("dir \n")
time.sleep(2)
print(p.readAllStandardOutput())
print(p.readAllStandardError())
p.waitForFinished()
print("Finished")
print p.ExitStatus()
输出:
^{pr2}${时间流逝}
Finished
PySide.QtCore.QProcess.ExitStatus.NormalExit
QProcess: Destroyed while process is still running.
那么“dir \n
”命令从未发出过吗?在
在读取输出之前似乎需要close the write channel。在
这对我在WinXP上有效:
你的代码有几个问题。在
start(...)
方法不返回值,但waitForStarted()
返回值readAllStandardOutput()
之前,调用waitForReadyRead()
。在waitForFinished()
将不会返回(或仅超时),除非您执行该过程(命令提示符)实际退出对于您的示例,这应该是一个最基本的工作版本:
相关问题 更多 >
编程相关推荐