开发者

Getting console output from jar in c#

开发者 https://www.devze.com 2023-03-25 03:56 出处:网络
i have a jar which if i run from th开发者_运维问答e command line returns me a true or false printed to the console

i have a jar which if i run from th开发者_运维问答e 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消