运行一个外部程序并截取它的截图

时间:2013-02-03 09:50:19

标签: python windows screenshot

我想通过运行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窗口,然后睡觉并截取屏幕截图,我希望这些操作是同步的。我怎么能这样做?

0 个答案:

没有答案