7

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)

Olivier Melançon
  • 21,584
  • 4
  • 41
  • 73
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46

3 Answers3

10

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

ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
1

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'])
sth
  • 222,467
  • 53
  • 283
  • 367
0

You can use the following way:

import os
os.startfile("D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe")

What this piece of code does is, it simply opens the file using its windows assigned default program.

A disadvantage of this way of starting is that it won't return any process object. So in order to manage the process you need to use win32 packages or other.

akhi1
  • 1,322
  • 1
  • 16
  • 25