0

I have 3 discord bots. Sometimes their scripts close when my WiFi dips up and down (thanks, Comcast).

I have a little experience with batch but I am stuck coming up with a batch script that detects when a certain program closes.

Assume I have the following files:

bot1-1.py
bot1-2.py
bot2-1.py
bot2-2.py
bot-3.py

What's the best way to open these files again if they close?

I would like the batch program to detect when any of the python programs close and reopen them.

Thanks to all who attempt to find an answer.

EDIT: This question is very similar to Make a .batch file to start/stop a program?

2
  • 2
    Possible duplicate of Make a .batch file to start/stop a program? Commented Apr 10, 2019 at 14:58
  • @SachaDee I think that question you linked should work for my issue. Commented Apr 10, 2019 at 15:39

2 Answers 2

2

I guess that when the Internet drops, you get an error since of connection. Use try: and except:, so if there is no Internet the program won't close. I hope that helped

Sign up to request clarification or add additional context in comments.

Comments

1

I'd advise you not to use a batchfile for that: just as your Python scripts can be closed, so can you batchfile.

You can register your scripts as services. Like that, Windows technology itself will make sure that your Python scripts keep running.

If you really want to use a batchfile for that, you might need one of the following commandline commands:

tasklist          // for finding is Python is running
wmic process list // for finding which Python script is running

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.