0

Why does the following print a blank line instead of 'Hello QProcess'?

import sys

from PyQt4 import QtGui, QtCore

proc = QtCore.QProcess()
proc.start("echo 'Hello QProcess'")
proc.waitForFinished()
result = proc.readAll()
print result
proc.close()

I'm on Windows XP, btw.

Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75

2 Answers2

2

Because there's no program called "echo".

If you wanted to run this through the shell then you should have used "cmd /C echo Hello QProcess".

Your program also has no error checking. If you'd checked for errors properly the mistake would have been easier to spot.

rohanpm
  • 4,264
  • 17
  • 16
0

You should provide system environment to your proc.

proc.setEnvironment(QProcess::systemEnvironment());

echo is exceptional command in Windows that does not have executable.

smitrp
  • 1,292
  • 1
  • 12
  • 28