How to build the game to be controlled by another program?

Hi everyone, I want to use UE5 for simulating a system and analyze the output. After building the game I need to feed the input to the application manually using C++ and get the value of the variables associated to specific objects in the scene at each frame and I don’t need the scene to be rendered visually. In other words I only need the output of physics engine. What is the right way to do it?
Thanks!