'Automate sending CMD command in specific window using python

I'm running a couple of things on my home server, two of which are Minecraft servers. I want to set up an automatic restart of the computer every week, but first want to close the servers in the correct way. This is done by sending the command "stop" in their specific CMD windows.

I've successfully been able to select and open specific CMD windows as shown below:

import pygetwindow as gw

handle = gw.getWindowsWithTitle('C:\Windows\system32\cmd.exe')[0]
handle.activate()

My problem is that I can't seem to be able to send the "stop" command in those specific windows. If I for example run the following commands instead:

import pygetwindow as gw
import os

print(gw.getAllTitles())
handle = gw.getWindowsWithTitle('C:\Windows\system32\cmd.exe')[0]
handle.activate()
os.system("stop")

It doesn't do anything because it opens a new CMD window. There might be other issues as well, but since I haven't been able to solve that issue I haven't encountered them yet.

I would really appreciate some help, cause I'm stuck.



Solution 1:[1]

I would use a plugin like AutoRestart https://www.spigotmc.org/resources/autorestart.2538/ for Spigot. If you're on vanilla, I would reccomend upgrading to Spigot (or i like to use Pufferfish/Paper)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GavinGoGaming