- Home /
Get Console or Debug.Log output from Unity command line batch mode and custom build process
I'm working on a small automated build process for my current project. I'm calling Unity in batch mode from within a WinForms C# application similar to this:
"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -projectPath xxx -logFile xxx -executeMethod MyBuilder.MyBuildMethod -someMoreArgs
In Unity I have the MyBuilder.MyBuildMethod which performs my automated build. Unity has its own logFile, which I can add to by using Debug.Log().
The documentation says: "Note that in batch mode, Unity sends a minimal version of its log output to the console." How do I get this console output in my calling application?
I've tried to RedirectStandardOutput, but it only returns an empty string. I'd like to read Unity's "minimal output" and optionally my own by using Debug.Log or Console.WriteLine.
Here is my WinForms C# code for starting the build:
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Settings.Default.UnityFilePath,
Arguments = GetBuildArguments(),
UseShellExecute = false,
RedirectStandardOutput = true,
}
};
p.Start();
Console.WriteLine("Begin read output");
Console.WriteLine(p.StandardOutput.ReadToEnd());
Console.WriteLine("Done read output");
p.WaitForExit();
Edit:
As of January 2017, Unity doesn't send standard output on Windows. I've read that it would work on Mac OSX, but not sure how adequately that performs. I have settled on the more hacky solution of adding a FileSystemWatcher to report on changes to the Unity log file and also reading every couple of seconds and log those lines from the file that are new. Only watching file changes also didn't work, because this would require that Unity would immediately write their statements into the file and mark the file as changed, but of course it only happens in certain chunks, which is why I also had to check every couple of seconds. The produced feedback was a little delayed, but good enough for me.
I am looking forward to improvements in this sector. Unity mentions a couple of features concerning build reporting on their roadmap and I hope this will include a public API for users or at least some better callbacks and data to query.
@Xarbrough I see this is old and no one replied to you. Just curious if you found an answer for this. Thanks.