Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting console output from jar in c#

i have a jar which if i run from the command line returns me a true or false printed to the console

i am trying to run this from c# and obtain the result - this is being 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;

I seem to be always getting an empty string and was wondering why this might be, or if there was a better way of doing it?

like image 866
James Avatar asked Aug 04 '11 19:08

James


1 Answers

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

like image 143
jonathanpeppers Avatar answered Nov 16 '22 10:11

jonathanpeppers