0

Basically, this script allows me to do a quick google map search if I press Win+R and type mapit (my script's name) and then the address (eg. mapit Market Street). Currently, the cmd stays open when there is or there is no exception raised. I would love for it to close if there is no errors or exception raised. The first script is my batch file while the second one is my python script. (ps. I'm a beginner)

@py C:\Users\<Name>\AppData\Local\Programs\Python\Python38-32\mypythonscripts\mapit.py %*
@pause
#! python3

import webbrowser, sys, pyperclip

Address = ' '.join(sys.argv[1:])

if len(sys.argv) <= 1:
    raise Exception ('Please type in address or postal after \'mapit\'')
else:
    webbrowser.open('https://www.google.com/maps/search/' + Address)

Thomas
  • 174,939
  • 50
  • 355
  • 478
JustANoob
  • 11
  • 1
  • Check out https://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line#334890 – Thomas Feb 08 '21 at 15:06

1 Answers1

0

You can use sys.exit() to close the program. You can actually specify a reason inside the parenthesis. E.g. sys.exit("Everything Worked")

Kelo
  • 1,783
  • 2
  • 9
  • 21