当我使用python.exe运行它时,我有一些Python代码可以正常工作,但如果我使用pythonw.exe则会失败.
def runStuff(commandLine):
outputFileName = 'somefile.txt'
outputFile = open(outputFileName, "w")
try:
result = subprocess.call(commandLine, shell=True, stdout=outputFile)
except:
print 'Exception thrown:', str(sys.exc_info()[1])
myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...'])
myThread.start()
我收到的消息是:
Exception thrown: [Error 6] The handle is invalid
但是,如果我没有指定'stdout'参数,则subprocess.call()启动正常.
我可以看到pythonw.exe可能正在重定向输出本身,但我不明白为什么我被阻止为新线程指定stdout.