The best way would be to instantiate the Process and capture the output using a stream like this:
Process cmd = new Process(); cmd.StartInfo.FileName = "JAVA.exe"; cmd.StartInfo.Arguments = "-Xmx256m jar.name"; cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.CreateNoWindow = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.EnvironmentVariables.Add("VARIABLE1", "1"); cmd.Start(); StreamReader sr = cmd.StandardOutput; string output = sr.ReadToEnd(); cmd.WaitForExit();
source share