-1

this is the code that I wrote:

import subprocess

rocket_league_path = 'D:\rocketleague\Binaries\Win64\RocketLeague.exe'
subprocess.Popen(rocket_league_path)

this is the error it shows to me:

Traceback (most recent call last):
  File "c:\Users\Marco\Desktop\Untitled-1.py", line 7, in <module>
    subprocess.Popen(rocket_league_path)
  File "C:\Users\Marco\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Marco\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Cannot find the specified file

I have tried with other applications and it works with all except Rocket League

Random Davis
  • 6,662
  • 4
  • 14
  • 24
Marco4521
  • 3
  • 1

1 Answers1

0

It's a quirk of the way string literals work in Python. The \ character is special, it indicates that the following characters may be interpreted as a special character. Or it may not, depending on what follows. In your case the two characters \r are being converted to a single character Carriage Return. The path is now incomplete and the file can't be found. If it had been \c instead it would have worked, because there's no special character corresponding to \c.

You can easily fix it by using a raw character string instead, where the \ loses its special meaning.

rocket_league_path = r'D:\rocketleague\Binaries\Win64\RocketLeague.exe'
#                    ^
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622