I've got the following bit of C# code running on .NET Core 2.2 to launch a Java process and wait for its execution:
using (var validator = new Process())
{
validator.StartInfo.FileName = "java";
validator.StartInfo.Arguments = finalArguments;
validator.StartInfo.UseShellExecute = false;
validator.StartInfo.RedirectStandardOutput = true;
validator.StartInfo.RedirectStandardError = true;
try
{
validator.Start();
validator.WaitForExit();
}
When run on Linux, this code works absolutely fine - Java process runs and exits.
When run on Windows, the Java process will just hang for a long while for some reason and not properly exit:
If I pause the debugger, the debugger pauses on validator.WaitForExit();
. If I kill the Java process manually, my application continues as normal.
What could be making the Java process hang and not exit correctly on Windows?
Edit: I'm running my function async so it doesn't hang the application, in case it makes a difference:
Task<OperationOutcome> validateWithJava = Task.Run(() => ValidateWithJava());