简体   繁体   中英

opening a batch file but when it opens my python code is stopped because the batch file opens in the same window

So I am basically trying to open and close a batch file (that runs a minecraft server) at specific times. The thing that is bothering me though is that when the file opens it does so in the same window as my script and therefore basically stops my code which consiquently means that the file will have to be manually closed. I was wondering if there is a way to open it in a separate window. This is thd code I have so far:

import os
import time
print "updates ever 15 mins = 0.25 hours"
hours = input("Current time (nearest 0.25 hour): ")
x = input("Opening time (hour): ")
y = input("Closing time (hour): ")
os.system ("cls")
os.chdir ("C:\\Users\\USERNAME\\Desktop\\Server")
while True:
    os.system("cls")
    time.sleep(900)
    hours += 0.25
    difx = x - hours
    dify = y - hours
    if difx == 0:
        os.popen("run.bat")
    if dify == 0:
        os.system ("say  CLOSING in 10 SECONDS")
        time.sleep (10)
        os.system ("stop")
        os.system ("taskkill /f /im cmd.exe")
    if hours == 25:
        hours = 1

stop is a command that stops the server running and saves all the info but leaves the window open (hence the taskkill command). Any help would be much appreciated.

将os.popen(“ run.bat”替换为os.startfile(“ filepath \\ run.bat”)应该可以。(谢谢)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM