How to execute .jar file in c#
-
Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.
-
Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.
If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try
Process proc = Process.Start("java", "-Xms60m....");
Also, make you that java exec is in your env path, otherwise supply full path to it. -
If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try
Process proc = Process.Start("java", "-Xms60m....");
Also, make you that java exec is in your env path, otherwise supply full path to it.Thanks for the answer dude, but it's not working still, i dont get an exception, just a ms-dos window for a second. Process proc = Process.Start("java", "java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); proc.EnableRaisingEvents = false; proc.WaitForExit(); Have i write it correctly? I really don't understand why waitForExit is neither working..
-
Thanks for the answer dude, but it's not working still, i dont get an exception, just a ms-dos window for a second. Process proc = Process.Start("java", "java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); proc.EnableRaisingEvents = false; proc.WaitForExit(); Have i write it correctly? I really don't understand why waitForExit is neither working..
FINALLY IS WORKING!!! Here is the code, thanks for ur time.. string path = "C:\\Programming"; Process process = new Process(); process.EnableRaisingEvents = false; process.StartInfo.FileName = "java.exe"; process.StartInfo.Arguments = "-jar " + '"' + path+ "\\interface.jar"; process.Start();
-
Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.
Hi, Use the following code to run .jar file from c# private int ExecuteProcess(string cmd, string cmdParams, string workingDirectory, int timeout, out string stdOutput) { using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams))) { process.StartInfo.WorkingDirectory = workingDirectory; //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); stdOutput = process.StandardOutput.ReadToEnd(); process.WaitForExit(timeout); return process.ExitCode; } } string stdOutput; string parameters = "Prajwal"; int exitCode = ExecuteProcess(@"C:\Program Files\Java\jre1.6.0\bin\Java.exe", " -jar samplejarfilename.jar " + parameters ,path, 5000, out stdOutput );