我正在尝试创建一个打开程序的脚本。我有一个命令,我通常在Windows运行中手动运行(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"')
当我运行时,我收到错误:
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
你可能已经看到我对此很新,但如果有人能帮助我,我会非常感激。
答案 0 :(得分:0)
"\0"
是NUL字符 - ord('\0') == 0
。它会在您的问题中导致TypeError
。
使用r"\0"
获取两个符号:反斜杠加小数零 -
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"
])
注意:引号内没有引号。