Windows: keep the output of an executable started without standard handles in anyps5.log #3282
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by justdoston on 2026-10-11T05:07:39Z.
Summary
A Windows executable started without a standard output or error handle loses everything it prints. This mostly affects a
--windows-guibuild started from Explorer, but any start without handles does the same. The lost output includes the entry stub's own messages (FAIL: unresolved ELF import …,Failed to load module: …), the libraries'stdout/stderr, uncaught exception messages and the crash reports fromCrashReport.cpp. All that is left is an exit code such as0xc0000135.Proposal
Before the entry stub enters its directory or loads a library, it checks the standard output and error handles. It gives each missing one
anyps5.logbeside the executable (CreateFileW,CREATE_ALWAYS,FILE_SHARE_READ | FILE_SHARE_WRITE, thenSetStdHandle). The executable imports onlyKERNEL32.dll, so the C runtime of the libraries the stub loads afterwards starts up with the file as itsstdout/stderr.Branch
justdoston/AnyPS5
feat/windows-log-without-standard-handles(262e38fd, onmain961b25fe):WindowsEntryStubBuilder.cpp: the check and theanyps5.logfile, written for the standard output and error handles.WindowsImportBuilder.cpp: importsCreateFileWandSetStdHandle.test_windows_import_modules.py: the two GUI start-up failure cases that run without handles now also check thatanyps5.logholds the failure message. The console case checks that no log is created.docs/user/USAGE.md: one sentence.Verification
-fsyntax-onlyfor both changed files.CreateProcessWwithSTARTF_USESTDHANDLESand no handles:FAIL: unresolved ELF import absent from a.prx(exit0xc0000139).Failed to load module: …(exit0xc0000135).printf/fprintf(stderr)lines in the log.I have not tested it on native Windows yet. A run from Explorer on real Windows would be welcome.
AI-assisted: yes. Claude (Anthropic) did most of the design, code and testing. I reviewed it and ran it.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T05:27:02Z.
Native Windows run of
262e38fdmerged ontomain961b25fe: Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, relinker-only build (ANYPS5_RELINKER_ONLY=ON), Python 3.12 (os.name == 'nt', so the Windows-only cases run).ctest: 100/100, includingwindows_import_modules. It builds without warnings.test_windows_import_modules.pyrun against a relinker built frommainfails at the new check (AssertionError: ('missing-symbol-gui', False), noanyps5.log). With the branch's relinker it passes.I also converted three
--windows-guicases with the test's ownprovider/executablehelpers. I started each one through the test'sexit_code_without_standard_handles(CreateProcessW,STARTF_USESTDHANDLES, no handles). I did not start them from Explorer itself.anyps5.log0xc0000139FAIL: unresolved ELF import absent from a.prx, the searched libraries,GetLastError: 1270xc0000135Failed to load module: …\libs\missing.prx,GetLastError: 1260xb(11)Transferring control to ELF entry pointSo on native Windows the stub output reaches the log in all three cases, and a successful GUI start also writes one. In the console runs of the test, no log is created.
One small thing, not from this branch: the missing-library log begins with a bare
-> FAILEDline. Without dependency diagnostics, theLoading …prefix isn't printed. A console run of the same case onmainprints the same orphan line, so it's existing behaviour, but it's more visible now that it's the first line of a file.Imported from boykopovar/AnyPS5. Originally posted by Jnbla6 on 2026-10-11T07:07:02Z.
Regarding the bare
-> FAILEDline @AchrafReyani noted on the missing-library path:WindowsEntryStubBuilder::BuildguardswriteString(loading)andwriteString(loaded)behindif (dependencyDiagnostics), but emitswriteString(loadFailed, true)unconditionally.I opened #3307 with a branch ready (
Jnbla6/AnyPS5fix/windows-stub-orphan-failed-line,3f85c8e4ec695dfe458e78a4b303c5981fcedd35) that guardswriteString(loadFailed, true)behindif (dependencyDiagnostics)as well.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-11T09:00:52Z.
Native Windows run of @thedrowned925's
fix/3282-windows-logging(619a1d46), merged into currentmain1c75f4d2(clean merge): Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, full build with the system libraries.End to end, the #1127 scenario. The
test_windows_import_modules.pyexecutable (exit 22 once its guest entry runs) converted as--windows-guiand as console, each started through ShellExecute (Start-Process, as Explorer does, so no standard handles), plus the GUI build again with handles captured:mainmain+ branchanyps5.log:Transferring control to ELF entry point0xc0000139, output lost0xc0000139,anyps5.log:FAIL: unresolved ELF import absent from a.prx,Searched libraries: …0xc0000135, output lost0xc0000135,anyps5.log:Failed to load module: …\libs\missing.prxExit statuses are unchanged in every case; only the output that had nowhere to go now lands in the file.
Full ctest: 814/816.
windows_import_modulespasses with the branch's new cases. The two failures also fail onmainhere:pr_overlap_encoding(Python 3.10) andguest_ampr_markers, which fails intermittently on plainmain1c75f4d2(6 of 10 runs alone,GuestAmpr.cpp:381).I did not test the system libraries' own output (an uncaught exception or a crash report from a
.prx) reaching the file, as that needs a fixture that loads them.