-1

I'm trying to make a script that opens a program. I have a command that I normally run manually in a Windows run (Windows Key + R).

command "C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 95.172.65.26:8088 kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa 945850509 EUN1"

import subprocess
subprocess.call('"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.53\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 95.172.65.26:8088 kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa 945850509 EUN1"')

When I run this, I get an error:

Traceback (most recent call last):
  File "C:\Users\Duran\Desktop\helloworld.py", line 2, in <module>
    subprocess.call('"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.53\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 95.172.65.26:8088 kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa 945850509 EUN1"')
  File "C:\Python34\lib\subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Python34\lib\subprocess.py", line 858, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child
    startupinfo)
TypeError: must be str without null characters or None, not str

You probably already saw I'm pretty new to this but if someone could help me I would really appreciate it.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
PHPeter
  • 567
  • 6
  • 19
  • try `subprocess.call([r'C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe', '8394', 'LoLLauncher.exe', 'spectator', '95.172.65.26:8088', r'kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa', '945850509', 'EUN1'])` – Himal Sep 10 '14 at 10:28
  • Can you explain what you did, why the [], r, ect. – PHPeter Sep 10 '14 at 12:13
  • Did it work ?. take a look at [subprocess](https://docs.python.org/2/library/subprocess.html) and [“u” and “r” string in Python](http://stackoverflow.com/a/2081708/1189040) for more info. – Himal Sep 10 '14 at 12:42
  • It did not work entirely, it started the program but the program returned with an error for some reason. when I type the command in to windows run it works, so there must be a mistake somewhere. – PHPeter Sep 10 '14 at 12:50
  • try this.`subprocess.call([r'"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe"', '"8394"', '"LoLLauncher.exe"', '""', r'"spectator 95.172.65.26:8088 kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa 945850509 EUN1"'])` – Himal Sep 10 '14 at 13:02
  • Now i get the same error as in my origional post except i don't get a TypeError but i get this: "PermissionError: [WinError 5] access Denied" BTW I translated "access denied" – PHPeter Sep 10 '14 at 13:27

1 Answers1

0

"\0" is NUL character -- ord('\0') == 0. It leads to the TypeError in your question.

Use r"\0" to get two symbols: the backslash plus the decimal zero --
list(map(ord, r'\0')) == [92, 48].

from subprocess import check_call

check_call([
    r"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe",
    "8394",
    "LoLLauncher.exe",
    "",
    "spectator 95.172.65.26:8088 kbbaZXzvdjwL2tHtX7XGaEG17tJQLVBa 945850509 EUN1"
])

Note: there are no quotes inside quotes.

jfs
  • 399,953
  • 195
  • 994
  • 1,670