Not sure if this is actually possible, but I would like to run from Unity editor, an exe that I wrote, and read its return value.
Basically I wrote a small automation in python that read and convert some assets in a different format; and I want to run this exe from Unity, for testing purpose (so I do not have to do it by hand, and can just do it from the editor, it is kinda like running automation tests in Unity for my code, but without write code in C#).
I read that I can trigger exe from Unity code; although I was not able to find an example about how you do that; and also I am trying to figure out if after running my exe file, I can read its return code. My exe return a string that contain âpassâ or âfailâ if the conversion of the assets is successful or not, so I would like to read that returned value in Unity, so I know if the application should continue, or should stop, since the conversion failed.
Any suggestions or examples I can look at? Assuming this is actually feasible of course. I wonder if I have to re-write my asset conversion again in C#, although it feels reductive to have to write your tools in C#, because Unity canât interface with external EXE.
You can do this using the ProcessStartInfo class. Hereâs an example that runs a command and outputs the return values and errors (run this with ârunShell=falseâ to get output to your Unity code or ârunShell=trueâ to run it through the dos prompt).
If itâs a python script, you can do what @tonemcbride is suggesting, but use âpythonâ for the command and â-m path-to-scriptâ for the args. That is, assuming that python is on your PATH.
Thatâll allow you to not have to compile the python code every time you make a change.