1

我想通过运行 100 次并截取正在运行的东西的屏幕截图来测试我的应用程序。这就是我想出的:

import sys, string, os
import time
import wx

directory = 'my path to directory containing the .exe'
file = '"directory and .exe path"'

app = wx.App(False)
screen = wx.ScreenDC()
size = screen.GetSize()   

def runprogram(number,sleep_time):
    bitmap = wx.EmptyBitmap(size[0], size[1])
    mem = wx.MemoryDC(bitmap)
    newfile = str(number) + "_" + str(sleep_time)
    print newfile
    os.chdir(directory)
    os.system(file)
    time.sleep(sleep_time) #seconds
    print "sleeping done"
    mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
    del mem
    bitmap.SaveFile(newfile, wx.BITMAP_TYPE_PNG)
    print "file saved as "+ newfile
    os.system("TASKKILL /F /IM myprogram.exe")

runprogram(1,5)

问题是,当执行 os.system() 时,脚本会停止,直到我关闭 myprogram 窗口,然后休眠并截屏,我希望这些操作是同时进行的。我怎样才能做到这一点?

4

0 回答 0