Python即使在中设置了close\u fds=True,也会打开一个文件两次子流程.Popen

2024-05-14 08:29:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用close\u fds=True子流程.Popen但还是要打开文件两次。我找了很多,但找不到解决办法。你知道吗

我想打开一个文件并截图。你知道吗

 import os
    import pyscreenshot as ImageGrab
    import subprocess as sp
    import time

    def imagegrabber(x=0):
        if(x==1 and __name__ == '__main__'):
            # part of the screen
            im=ImageGrab.grab(bbox=(50,70,500,500))
            im.show()

        # to file
            ImageGrab.grab_to_file('im.png')
        return;

    def Dashboard(x=0):
        if(x==1):
            mcr = "D:/MCR/test.pbix"
            path = r'C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe'
            sp.Popen([path,mcr],close_fds=True)
            time.sleep(10)
            imagegrabber(1)
        return;

    Dashboard(1)

Tags: 文件importtruecloseiftimedefas

热门问题