Reputation: 3
I have a menu for my discord bot, and my discord bot has a starter bat file, it just starts the python file. But in the menu, I want to create a restart button for the bot, but I can't. I only want to stop the file, then start it again. I tried to use os.close, but I've got an error: "an integer is required (got type str)"
def stop():
os.close('C:\\Codeok\\Discord_bot\\bot_start.bat')
That's how the code for the off button.
Upvotes: 0
Views: 189
Reputation: 310
dont just spawn the python process. use this:
wmic process call create "D:\Python39\python.exe c:\xx.py"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = 1234;
ReturnValue = 0;
};
This would give the pid. Save it somewhere and then when the time comes to restart, kill the pid process using:
TASKKILL /PID 1234
Upvotes: 1