How to collect LogStats output when running commands from a python script?

I am trying to write a python script that will load assets one after the other and run ‘stat startfile’ for a few seconds and the then run ‘stat stopfile’. I would like to be able to specify an output file for stat startfile/stopfile, but I don’t see a way to do that. As a workaround, I would like to get the name of the file that is written to the output log like this…

LogStats: Wrote stats file: …/…/…/MyGame/Saved/Profiling/UnrealStats/Untitled_1-Windows-08.10-13.03.52/Untitled_10-Windows-10-15.15.19.ue4stats

…so that I can move the folder to one that includes the name of the asset I just loaded.

How can I capture that line from the output log so that I can use it in my python script?

I found this command…


but it’s not very clear to me how to use it, or if it’s really what I want. Any help appreciated.

Note to self: I wrote some python to find the most recent ue4stats file and rename it. When I tried to load it in Session FrontEnd the editor crashed.