简体   繁体   English

在c#中从jar获取控制台输出

[英]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 我有一个jar,如果我从命令行运行返回我一个真或假打印到控制台

i am trying to run this from c# and obtain the result - this is being done like this 我试图从c#运行它并获得结果 - 这是这样做的

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? 我好像总是得到一个空字符串,并想知道为什么会这样,或者是否有更好的方法呢?

设置RedirectStandardError并调用p.StandardError.ReadToEnd()读取进程的任何错误输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM