Getting console output from jar in C #

I have a jar that, if I run from the command line, returns me true or false printed on the console

I am trying to run this from C # and get the result - this is done like this:

Process p = new Process(); p.StartInfo = new ProcessStartInfo("java", @"-jar test.jar " + paramterForStringArgs[0]); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); String s = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Trace.WriteLine("data = " + s); return false; 

It seems I always get an empty string and wondered why this could be, or if there is a better way to do this?

+6
source share
1 answer

Setting up a RedirectStandardError and calling p.StandardError.ReadToEnd() reads any error result from the process.

+5
source

Source: https://habr.com/ru/post/894320/


All Articles