我需要从Java控制台应用程序获取输出(显示的数据),以便通过我的VB.net应用程序进行解析。我还需要向应用程序发送输入。我怎样才能完成这两项任务?
答案 0 :(得分:1)
您应填充ProcessStartInfo
对象,启动Java控制台应用程序的过程,并阅读其输出:
ProcessStartInfo startInfo = new ProcessStartInfo();
// specify the address of your java app
startInfo.FileName = "JVM_PATH_HERE.EXE";
// input for your java app
startInfo.Arguments = "-jar JAVA_APP_PATH_HERE.exe";
// do not show your java app window
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
// redirect standart input/output for your needs
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
using (Process javaProc = Process.Start(startInfo))
{
StreamReader oReader2 = p.StandardOutput;
// get results from your java app
string javaResults = oReader2.ReadToEnd();
oReader2.Close();
// do whatever your like with results;
AnalizeResults(javaResults);
}