简体   繁体   English

Python 打印屏幕执行提示命令的脚本

[英]Python Script to printscreen execution of prompt commands

I'm building a python script to a college work, that it executes some prompt commands and save a screenshot of the execution, but i'm having trouble with clearing the screen(clear/cls) between every screenshot (to look cleaner) here's my script:我正在为一项大学工作构建一个 python 脚本,它执行一些提示命令并保存执行的屏幕截图,但我无法在每个屏幕截图之间清除屏幕(清晰/cls)(看起来更干净)这里是我的脚本:

import pyautogui
import subprocess
import time

comands_list = open('comandos.txt').read().splitlines()

for i in range(len(comands_list)):
    comando = comands_list[i]
    print("Comando executado: " + comando)
    s = subprocess.getstatusoutput(comando)
    print("Resultado da execução: \n" + s[1])
    try:
        myScreenshot = pyautogui.screenshot()
        myScreenshot.save(comando+'.png')
        print("Captura de tela salva com sucesso!")
    except:
        print("Captura de tela não salva!")
    subprocess.getoutput("clear")
    #time.sleep(3)

Any help is welcome, thanks!欢迎任何帮助,谢谢!

To clear the python outputs, do something like this: (Note, this does not work for IDLE python shell, you should just double click on the python program to execute it)要清除 python 输出,请执行以下操作:(注意,这不适用于 IDLE python shell,您只需双击 python 程序即可执行它)

import pyautogui
import subprocess
import time
import os
clear = lambda: os.system('cls')
commands = ["echo hi", "echo hello"]
for i in range(len(commands)):
    c = commands[i]
    s = subprocess.getstatusoutput(c)
    print(s)
    try:
        screenshot = pyautogui.screenshot()
        screenshot.save(str(i+1)+'.png')
        print("Success")
    except:
        print("Error")
    subprocess.getoutput("CLS")
    time.sleep(3)
    clear()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM