Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Stardew Valley from python on Windows

Currently I am trying to run Stardew Valley from python by doing this:

import subprocess
subprocess.call(['cmd', 'D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe'])

However, this fails and only opens a CMD window. I have a basic understanding of how to launch programs from python, but I do not understand how to specifically open a program that is located not only in a different location, but also on a different drive.

Any help would be appreciated. Thanks!

Edit:

This is on windows 10

Stardew Valley version is the beta and is located on the D:/ drive (windows is on C:/ of course)

like image 893
Ryan Schaefer Avatar asked Jun 14 '18 01:06

Ryan Schaefer


2 Answers

Can you try using the steam commandline using the appid of the game:

subprocess.call(r"C:\Program Files (x86)\Steam\Steam.exe -applaunch 413150")

you can find the app id in the "web document tab" from the desktop shortcut properties
(which can be generated by right click and select create desktop shortcut in the steam library). It will be something like this steam://rungameid/413150

like image 194
ClumsyPuffin Avatar answered Oct 01 '22 14:10

ClumsyPuffin


You don't have to use cmd, you can start the .exe directly.

Additionally you should be aware that \ is used to escape characters in Python strings, but should not be interpreted specially in Windows paths. Better use raw strings prefixed with r for Windows paths, which disable such escapes:

import subprocess
subprocess.call([r'D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe'])
like image 22
sth Avatar answered Oct 01 '22 13:10

sth