Wondering if anyone knows a nice way to execute a Java command-line program from C# code at run-time ?
Is it the same as executing native .EXE files ?
Wi
I added a couple of lines to the above solution. I wanted to call a Web Service from a Silverlight app that process some files using java on the server. The above solution is helpful but I modified a little bit so that it works since calling via a web service is a little bit trickier. Now you have the right tool for the job, C# when appropriate, Java when C# cannot solve the problem. It's always good to know more than just one way of doing things. Now my Web Service created in .Net can talk to Java.
private void Merge(string strPath)
{
var processInfo = new ProcessStartInfo("C:\\Program Files\\Java\\jdk1.6.0_24\\binjava.exe", "-jar app.jar")
{
CreateNoWindow = true,
UseShellExecute = false
};
processInfo.WorkingDirectory = strPath; // this is where your jar file is.
Process proc;
if ((proc = Process.Start(processInfo)) == null)
{
throw new InvalidOperationException("??");
}
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
}