python - определить, открылась ли другая программа или скрипт - PullRequest
0 голосов
/ 23 марта 2020

Я сделал лаунчер, чтобы открыть несколько python программ и некоторые игры, у которых нет своих лаунчеров. когда я делаю опечатку, открывающую программу python, она не открывается и выдает мне сообщение об ошибке, а затем завершает программу. Есть ли способ заставить программу обнаруживать погоду или нет она была открыта или нет? мой код выглядит следующим образом (python 3.7):

import os                   #imports for what i need
import time
import sys
print("welcome to the p00nda launcher") #intro


def ui():   #help command output
    print("****************************************************************************************")
    print("this was created by our lord and savior p00nda chan to launch his shitty python programs")
    print("because he didnt want to keep switching between them and also he was very bored")
    print("****************************************************************************************") 
                                                                               #mainly used commands
    print("py.open                          - opens a python program")
    print("chrome.open                      - opens chrome")
    print("discord.open                     - opens discord")
    print("steam.open                       - opens steam")
    print('photoshop.open                   - opens photoshop')
    print("exit")                                                                       
    print("****************************************************************************************") 
                        #commands for misc games that are currently working or i am still working on
    print("game.Octopath                    - launches octopath traveller")
    print('game.huniepop                    - launches huniepop')
    print('game.xcom                        - launches xcom')
    print('game.partyhard                   - launches party hard')
    print("")    #seperate the help section of text from the main section of text when run
    main()

def main(): #area where inputs are given by user
    print("what would you like to do (type help for more options)")                                 
                                                                          #asks question
    choice = input("")      #input given on a seperate line because i dont like it when you type on 
the end of what was just printed
    print("") #seperate different parts of text

    if choice == "help":
        ui()

    elif choice.lower() == "exit":           #other options that arent help
        close()
    elif choice.lower() == "py.open":
        py_open()
    elif choice.lower() == "chrome.open":
        chrome_open()
    elif choice.lower() == "discord.open":
        discord_open()
    elif choice.lower() == "steam.open":
        steam_open()
    elif choice.lower() == "game.octopath":
        game_octopath()
    elif choice.lower() == 'game.huniepop':
        game_huniepop()
    elif choice.lower() == 'game.partyhard':
        game_partyhard()
    elif choice.lower() == 'game.xcom':
        game_xcom()
    elif choice.lower() == 'photoshop.open':
        open_photoshop()


    else:
        print("you have entered an option that is not on the list or is not currently working, please")
        print("enter a working option that is on the list")
        print("")     #so that it dosent look like a wall of text
        main()

def close():     #exits program
    print("closing...")
    time.sleep(1)
    sys.exit()      #kills program


def py_open():
    print('"give the name of the python file you would like to open (must have .py at the end)"')
    os.startfile(str(input('')))  #asks for the name of the python file and opens it
    main()      #returns to main incase they would like to open something else

def chrome_open():
    print("opening chrome")     #tells user something is happening incase it takes long to respond etc
    os.startfile(r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')     #opens chrome
    main()


def discord_open():
    print("opening discord")
    time.sleep(3)                   #waits a second so that user sees the previous message
    os.startfile(r'C:\Users\alexa\AppData\Local\Discord\app-0.0.306\Discord.exe') #opens discord
    main()

def steam_open():
    print("opening steam") 
    time.sleep(3)
    os.startfile(r'D:\Misc. software\Games\Steam\Steam.exe')    #opens steam
    main()

def game_octopath():
    print("opening Octopath traveller")
    time.sleep(1)
    os.startfile(r'D:\Misc. software\Games\Octopath Traveler\Octopath_Traveler.exe')   #opens octopath
    main()

def game_huniepop():
    print('opening huniepop')          
    time.sleep(1)
    os.startfile(r'C:\GOG Games\HuniePop\HuniePop.exe') #opens huniepop
    main()

def game_partyhard():
    print("opening party hard")
    time.sleep(1)
    os.startfile(r'D:\Misc. software\Games\Party Hard 2\PartyHard2Game.exe') #opens party hard
    main()

def game_xcom():
    print('opening xcom')
    time.sleep(1)
    os.startfile(r'C:\GOG Games\XCOM Enemy Unknown\Binaries\Win32\XComGame.exe')    #opens xcom
    main()

def open_photoshop():
    print('opening photoshop')
    time.sleep(1)
    os.startfile(r'D:\Program Files (x86)\Adobe Photoshop CS6\Photoshop.exe')
    main()

main()              #starts program
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...