简体   繁体   中英

Launch Windows games from shell using Python

I want to execute and terminate Windows games from shell. The actual need is to launch games using Python upon receiving specific command. I have tried using the following code to launch game.

import subprocess

subprocess.Popen("D:/Entertainement/Games/NFS1/speed.exe",shell=False)

When I run this code, the game launches and stops without any errors. But the same game runs fine when executed from Windows Explorer. The game doesn't require administrative privileges and runs fine without that.

(Posted on behalf of the OP) .

I found a workaround. Instead of launching the executable directly, i created a shortcut and launched it with the following command.

import subprocess


p = subprocess.Popen("C:\Users\devel\Desktop\speed.exe.lnk",shell=True)
p.wait()
print("Program Exited with return code : "+str(p.returncode))

Now everything works fine and my Python program waits for the return code. Thank you all for replying.

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