יום חמישי, 6 ביוני 2013

Executing java jar from C-sharp

The following code execute a java jar from C# environment and capture back the standard output the jar generate.

  1: using System;
  2: using System.Collections.Generic;
  3: using System.Diagnostics;
  4: using System.IO;
  5: using System.Linq;
  6: using System.Text;
  7: using System.Threading.Tasks;
  8: 
  9: namespace SendTheEvent
 10: {
 11:     class Program
 12:     {
 13:         static void Main(string[] args)
 14:         {
 15:             ProcessStartInfo thePsi = new ProcessStartInfo ();
 16: 
 17:             thePsi.WorkingDirectory = @"C:\projects\myProjectWorkingDirectory";
 18: 
 19:             thePsi.FileName =@"C:\Program Files\Java\jre7\bin\java.exe";
 20: 
 21:             thePsi.RedirectStandardOutput = true;
 22: 
 23:             thePsi.UseShellExecute = false;
 24: 
 25:             thePsi.Arguments = "-jar ActiveMQNotifier.jar";
 26:        
 27:       using (Process process = Process.Start(thePsi))
 28:       {
 29:         //
 30:         // Read in all the text from the process with the StreamReader.
 31:         //
 32:         using (StreamReader reader = process.StandardOutput)
 33:         {
 34:           string result = reader.ReadToEnd();
 35:           Debug.Write(result);
 36:         }
 37:       }
 38:        }
 39:     }
 40: }

אין תגובות:

הוסף רשומת תגובה