Popen 成功运行一个程序,但 2 秒后出现访问冲突错误

问题描述 投票:0回答:1

我尝试使用 Popen() 打开视频游戏《网络奇兵 2》并使其保持打开状态,该进程打开,然后由于访问冲突而在大约 2 秒后关闭。没有窗户被打开。 Python 运行代码没有错误。 没有任何内容通过 stdout 或 stderr 传递。 它的返回代码为 3221225477,这是访问冲突错误代码。 在我测试过的所有其他情况下,游戏都可以正常打开。 这是我正在运行的代码。

from subprocess import Popen

SS2 = Popen(args="C:\Program Files (x86)\Steam\steamapps\common\SS2\ss2.exe")

我尝试使用几个 Windows 调试工具来查看它关闭的原因,以下是它们关闭之前的一些片段。

进程监视器将其显示为它开始关闭之前所做的最后一件事。

2:50:52.0748437 AM  ss2.exe 16848   RegCloseKey HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{5bf2a6f1-f431-4cbe-8692-8313eea088c3}\Properties SUCCESS 
2:50:52.0752768 AM  ss2.exe 16848   CreateFile  C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
2:50:52.0753113 AM  ss2.exe 16848   QueryDirectory  C:\Users\User\AppData\Local\Programs\Python\Python311\iface NO SUCH FILE    FileInformationClass: FileBothDirectoryInformation, Filter: iface
2:50:52.0753277 AM  ss2.exe 16848   CloseFile   C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS 
2:50:52.0754329 AM  ss2.exe 16848   CreateFile  C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
2:50:52.0754611 AM  ss2.exe 16848   QueryDirectory  C:\Users\User\AppData\Local\Programs\Python\Python311\iface.zip NO SUCH FILE    FileInformationClass: FileBothDirectoryInformation, Filter: iface.zip
2:50:52.0754755 AM  ss2.exe 16848   CloseFile   C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS 
2:50:52.0755746 AM  ss2.exe 16848   CreateFile  C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
2:50:52.0756017 AM  ss2.exe 16848   QueryDirectory  C:\Users\User\AppData\Local\Programs\Python\Python311\iface.crf NO SUCH FILE    FileInformationClass: FileBothDirectoryInformation, Filter: iface.crf
2:50:52.0756156 AM  ss2.exe 16848   CloseFile   C:\Users\User\AppData\Local\Programs\Python\Python311   SUCCESS 
2:50:52.0756812 AM  ss2.exe 16848   QueryNameInformationFile    C:\Program Files (x86)\Steam\steamapps\common\SS2\ss2.exe   SUCCESS Name: \Program Files (x86)\Steam\steamapps\common\SS2\ss2.exe
2:50:52.2105046 AM  ss2.exe 16848   Process Create  C:\WINDOWS\SysWOW64\WerFault.exe    SUCCESS PID: 16836, Command line: C:\WINDOWS\SysWOW64\WerFault.exe -u -p 16848 -s 2272
2:50:55.9768621 AM  ss2.exe 16848   Thread Exit     SUCCESS Thread ID: 16328, User Time: 0.0156250, Kernel Time: 0.0312500

VS JIT 调试器最后看到的东西是这样的。

'ss2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. 
'ss2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. 
'ss2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\MMDevAPI.dll'. 
'ss2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\AudioSes.dll'. 
'ss2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ResourcePolicyClient.dll'. 
The thread 0x2234 has exited with code 0 (0x0).
The thread 0x2ce8 has exited with code 3221225477 (0xc0000005).
The thread 0x4fdc has exited with code 3221225477 (0xc0000005).
The thread 0x499c has exited with code 3221225477 (0xc0000005).
The thread 0x6a8 has exited with code 3221225477 (0xc0000005).
The thread 0x1bbc has exited with code 3221225477 (0xc0000005).
The thread 0x3630 has exited with code 3221225477 (0xc0000005).
The thread 0x4d04 has exited with code 3221225477 (0xc0000005).
The program '[8692] ss2.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.

我尝试过的事情:在非提升和提升的脚本以及 python 终端中运行代码。在其属性中将 ss2.exe 设置为以管理员身份运行。 将 System Shock 2 目录移动到其他位置。 我已确保 Popen() 适用于其他 Steam 游戏。 在另外 2 台计算机上尝试过。 更新了 GPU 驱动程序。 尝试了新下载的未修改的《网络奇兵 2》副本以及使用 SS2Tool 进行修改的副本。 使用 shell=True 运行。 尝试了 asyncio.create_subprocess_exec 并得到了完全相同的行为。

python crash popen
1个回答
0
投票

我需要使用 cwd=("ss2.exe Parent dir") 将 ss2 文件夹的工作目录添加到 Popen() 中。 现在它按预期工作了。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.