- Home /
Console Output when using Batchmode (Windows)
Hey Guys, I am working on a CI pipeline for our Jenkins server. I currently have a script that builds my Unity project. It all works pretty well.
The only thing that is annoying me is the Console.WriteLine. I want to output Console.WriteLines() I have written in my script but they don't appear in my command prompt.
Has anyone had some luck with this?
Answer by moonshinebot · Jan 19 at 10:51 AM
Here's how I made it work using PowerShell 6+ and background jobs.
& 'C:\Program Files\Unity\Hub\Editor\2021.2.8f1\Editor\Unity.exe' -quit -batchmode -projectPath C:\myproject\ -logfile 'log.txt' &; Get-Content log.txt -Wait
This will launch Unity in batch mode writing all logs to a file log.txt
. It then puts Unity into a background job, using the background operator (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2#background-operator-). It then starts reading the file, waiting for any updates. Note that while this reads the file, it won't stop reading until closed - which is something that is probably doable using the Job system, too.