Important: Please read the Qt Code of Conduct -

QProcess use on Windows

  • In PySide and PyQt5 I start a process to kick off another Python GUI application like this:

    p = QProcess()
    p.start( "pythonw.exe", [ arg2, arg2 ], QIODevice.ReadOnly )

    In PySide2 this doesn't work (at least on Windows 10): nothing happens. startDetached doesn't work either.

    In C++ it looks like you now need to call setCreateProcessArgumentsModifier but I don't see any documentation on using this under Python.

    Any help would be greatly appreciated!


  • In lieu of setting up the environment, try explicitly setting the path to the python interpretter: pythonw.exe.

    also trap the signals that p.start can cause to be emmitted, to see why it is failing.

  • Thanks for the suggestions.

    Adding the explicit path to pythonw.exe doesn't make a difference -- the PATH already contains the pythonw.exe directory. As I said, all works fine with PySide or PyQt5.

    The start call isn't generating an exception and trapping the QProcess signals I get the finished signal firing with an exitCode of 1 and an exitStatus of PySide2.QtCore.QProcess.ExitStatus.NormalExit. If the start runs "dir" it works and I get an exitCode of 0 but if it runs "explorer" it also works but I get an exitCode of 1, so I'm not sure if the exitCode is significant.

    If start runs simply "pythonw.exe" I see a pythonw process running in Task Manager. But with my arguments it exits immediately. I checked that the same pythonw.exe command line works fine at the terminal.

    Can anyone shed light on what is going on here? Does PySide2 require something extra to open another PySide2 application from a QProcess? Or is QProcess buggy?


  • @DeadParrot said in QProcess use on Windows:

    In C++ it looks like you now need to call setCreateProcessArgumentsModifier but I don't see any documentation on using this under Python.

    So what happens when you do it in python exactly like you would in c++?

  • I don't see any documentation for calling setCreateProcessArgumentsModifier in PySide2 so I assume it isn't supported. But maybe someone knows more about this?

  • @DeadParrot well just try it, using the c++ docs as a model.

  • @Kent-Dorfman I agree that is the next step. Unfortunately, trying it gives:
    'PySide2.QtCore.QProcess' object has no attribute 'setCreateProcessArgumentsModifier'

    I'm going by an SO posting that may not be relevant to the issue I'm hitting.

  • OK, so the issue turned out to be something different. We are using QtPy and it needs the environment variable QT_API set to pyside2 for our Windows setup. For some reason the environment passed to QProcess isn't inheriting that variable and it was defaulting to pyside. Setting it manually to pyside2 by calling setProcessEnvironment on our QProcess before the start call gets everything working.

    Not sure if this is a PySide2 bug or not. The QProcess.execute documentation says:
    "The environment and working directory are inherited from the calling process."
    but it doesn't say this explicitly for start.

  • This post is deleted!