相关疑难解决方法(0)

忽略subprocess.Popen的输出

我从我的Python脚本调用java程序,它输出了许多我不想要的无用信息.我试过了对Popen stdout=None函数的addind :

subprocess.Popen(['java', '-jar', 'foo.jar'], stdout=None)
Run Code Online (Sandbox Code Playgroud)

但它也是如此.任何的想法?

python subprocess

10
推荐指数
2
解决办法
2万
查看次数

使用pythonw.exe时,Python subprocess.call()失败

当我使用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.

python multithreading subprocess

5
推荐指数
2
解决办法
5280
查看次数

标签 统计

python ×2

subprocess ×2

multithreading ×1