我正在尝试使用python3.7在windows10框上启动Dota2,并指定参数,使用asyncio.create\ u subprocess\ u exec(). 游戏当前启动,但参数似乎被忽略,因为它不会自动启动bot游戏,而只是Dota2应用程序。你知道吗
用subprocess
模块和Popen()
做一些类似的事情就可以了。你知道吗
import asyncio
from sys import platform
args = [
'C:\\Program Files (x86)\\Steam\\steamapps\\common\\dota 2 beta\\game\\bin\\win64\\dota2.exe',
'-con_logfile scripts/vscripts/bots/console.log',
'-con_timestamp',
'-console',
'-dev',
'-insecure',
'-noip',
'-nowatchdog',
'+clientport 27006',
'+dota_1v1_skip_strategy 1',
'+dota_surrender_on_disconnect 0',
'+host_timescale 1',
'+hostname dotaservice',
'+sv_cheats 1',
'+sv_hibernate_when_empty 0',
'+tv_delay 0',
'+tv_enable 1',
'+tv_title some_uuid',
'+tv_autorecord 1',
'+tv_transmitall 1',
'-fill_with_bots',
'+map',
'start gamemode 6',
'+sv_lan 1'
]
def main_func():
if platform == "win32":
asyncio.set_event_loop(asyncio.ProactorEventLoop())
loop = asyncio.get_event_loop()
tasks = offline_main()
loop.run_until_complete(tasks)
async def offline_main():
create = asyncio.create_subprocess_exec(args[0], ' '.join(args[1:]), stdin=asyncio.subprocess.PIPE, stdout=None, stderr=None)
await create
#main_func()
def sub_func():
import subprocess
p = subprocess.Popen('"'+args[0]+'" '+' '.join(args[1:]), stdin=subprocess.PIPE, stdout=None, stderr=None)
#sub_func()
如果您取消注释sub_func()
,它就可以正常工作。如果取消注释main_func()
,它将启动Dota2应用程序,但不会启动bot游戏。我知道传递的参数有细微的差别,但如果我使用:
create = asyncio.create_subprocess_exec('"'+args[0]+'" '+' '.join(args[1:]), stdin=asyncio.subprocess.PIPE, stdout=None, stderr=None)
我因为某种原因得到了PermissionError: [WinError 5] Access is denied
如果你把所有的参数都分开,包括你想设置它们的值,结果就是这样。你知道吗
以下工程代码:
相关问题 更多 >
编程相关推荐