从C代码犀利执行jar文件,得到的返回值 [英] Execute Jar file from C sharp code and get return value
问题描述
只是我要执行从C代码犀利的Jar文件,并从罐子返回值。这可能吗?
Just I want to execute the Jar file from C sharp code and get return values from jar. Is it possible?
如果因此给我的示例代码。
If so give me the sample code.
我想以后的事,
string path = "C:\\Documents and Settings\\Desktop";
Process process = new Process();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.FileName = "C:\\Program Files\\Java\\jre6\\bin\\java.exe";
process.StartInfo.Arguments = "-jar \"" + path + "\\simple.jar\"";
process.Start();
String s = process.StandardOutput.ReadToEnd();
下面simple.jar具有将采取arguements并打印在控制台通过arguemnets主要方法,否则它打印在控制台没有arguements。
我上面的代码试图在这一行(一个String = process.StandardOutput.ReadToEnd())。能够读取控制台值
here simple.jar has main method which will take the arguements and prints the passed arguemnets in console, otherwise it prints no arguements in console. I tried above code in this line(String s = process.StandardOutput.ReadToEnd();) able to read the console values.
但我想在罐子和方法传递值执行方法将返回我的HashMap(集合)的值(我不知道这是可能或没有)。
请给我建议这一点。
But I want to execute a method by passing values in jar and method will return me hashmap (collection) values(I don't know it is possible or not). Please give me suggestions on this.
推荐答案
要在命令行中使用<$ C $执行一个jar文件C>的java.exe -jar<&jar_name都GT; 。
看一看的此处看你怎么执行一个命令行程序,并得到其输出 C#
。
Take a look here to see how do you execute a command line program and get its output in C#
.
这篇关于从C代码犀利执行jar文件,得到的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!