C# Execution of Java program
-
Indeed, I missed the overloaded method in the docs. :-O You should still be able to get the ExitCode. Is the Process being started? Did you try the provided sample?
No comment
I based my code off of the provided sample. As far as I can tell the execute is occuring but when the process starts the system crashes.
Jerry W. Manweiler, Ph.D. Fundamental Technologies, LLC
-
I based my code off of the provided sample. As far as I can tell the execute is occuring but when the process starts the system crashes.
Jerry W. Manweiler, Ph.D. Fundamental Technologies, LLC
Is there no exception being thrown? Does the application run on its own, not using Process?
No comment
-
Is there no exception being thrown? Does the application run on its own, not using Process?
No comment
As I indicated in my original post, There are no exceptions thrown and the process works fine outside the C# environment That is why I'm looking for help in trying to understand what is going on.
Jerry W. Manweiler, Ph.D. Fundamental Technologies, LLC
-
I'm working on a project that requires my C# code to execute a Java program provided to me by my client. I create a new ProcessStartInfo and setup the process as follows: psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = the java executable to be run; psi.Arguments = the arguments for the code; psi.WindowStyle = hidden; I then execute the program using using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); } when I execute the process the code crashes without any information. Any thoughts on what I might be doing incorrect or any thoughts on trying to get more information about why the crash occurs. As a note, if I run this process outside my code in a command prompt then it works without failure. Thanks Jerry
Jerry W. Manweiler, Ph.D. Fundamental Technologies, LLC
Jerry W. Manweiler, Ph.D. wrote:
when I execute the process the code crashes without any information.
That says nothing. A crash suggests a system (OS) exception occurred. I doubt that is the case. Either nothing at all happened or something did just not what you wanted.
Jerry W. Manweiler, Ph.D. wrote:
psi.FileName = the java executable to be run;
psi.Arguments = the arguments for the code;In this context the above is non-sensical. There are two possibilities. 1. You are running a java application. 2. You are running a java executable jar. For the first it requires. 1. The java exectutable - java.exe 2. Appropriate class path 3. The FQN of the main class For the second it requires. 1. The java exectutable - java.exe 2. Appropriate jar 3. Appropriate command line options Regardless of the above the Process provides for the following A. The exe exit code B. Stdout C. Stderr The MOST likely failure is that the Process.ExitCode is 2 which means your "executable" (whatever that really is) is not pathed correctly or isn't even an executable (although then it is probably something besides 2.) If in fact java is running at all then there should be stdout/err output which, as noted above, you can extract for more information.
-
Jerry W. Manweiler, Ph.D. wrote:
when I execute the process the code crashes without any information.
That says nothing. A crash suggests a system (OS) exception occurred. I doubt that is the case. Either nothing at all happened or something did just not what you wanted.
Jerry W. Manweiler, Ph.D. wrote:
psi.FileName = the java executable to be run;
psi.Arguments = the arguments for the code;In this context the above is non-sensical. There are two possibilities. 1. You are running a java application. 2. You are running a java executable jar. For the first it requires. 1. The java exectutable - java.exe 2. Appropriate class path 3. The FQN of the main class For the second it requires. 1. The java exectutable - java.exe 2. Appropriate jar 3. Appropriate command line options Regardless of the above the Process provides for the following A. The exe exit code B. Stdout C. Stderr The MOST likely failure is that the Process.ExitCode is 2 which means your "executable" (whatever that really is) is not pathed correctly or isn't even an executable (although then it is probably something besides 2.) If in fact java is running at all then there should be stdout/err output which, as noted above, you can extract for more information.
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters. Regardless of the above, the Process dies by killing all associated running processes including the IDE. The entire process (java class parms) does run just fine if I do it outside my code. So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on. And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path); FileInfo\[\] files = di.GetFiles("\*.xml"); foreach (FileInfo file in files) { Text = "Converting: " + file.Name; String\[\] parms = new String\[1\]; parms\[0\] = file.FullName; ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = @"\\\\NASA\\GSFC\\CDF\\CDFML2CDF.exe"; psi.Arguments = file.FullName; psi.WindowStyle = ProcessWindowStyle.Hidden; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); Text = " Processing successful for file = " + file.Name; Text = " ---- Process output Begin---"; Text = exeProcess.StandardOutput.ReadToEnd(); Text = " ---- Process output End---"; } } catch { Text = " Processing failed for file = " + file.Name; } }
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die. There is nothing logged in the System or application event logs. There is nothing output to the system - IT JUST CRASHES the IDE and Threads. Do you have any helpful ideas or suggestions?
-
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters. Regardless of the above, the Process dies by killing all associated running processes including the IDE. The entire process (java class parms) does run just fine if I do it outside my code. So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on. And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path); FileInfo\[\] files = di.GetFiles("\*.xml"); foreach (FileInfo file in files) { Text = "Converting: " + file.Name; String\[\] parms = new String\[1\]; parms\[0\] = file.FullName; ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = @"\\\\NASA\\GSFC\\CDF\\CDFML2CDF.exe"; psi.Arguments = file.FullName; psi.WindowStyle = ProcessWindowStyle.Hidden; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); Text = " Processing successful for file = " + file.Name; Text = " ---- Process output Begin---"; Text = exeProcess.StandardOutput.ReadToEnd(); Text = " ---- Process output End---"; } } catch { Text = " Processing failed for file = " + file.Name; } }
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die. There is nothing logged in the System or application event logs. There is nothing output to the system - IT JUST CRASHES the IDE and Threads. Do you have any helpful ideas or suggestions?
Hi Jerry, Try saying:
psi.UseShellExecute = true;
instead. (Really just a shot in the dark, but I think it's worth a try.)
The difficult we do right away... ...the impossible takes slightly longer.
-
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters. Regardless of the above, the Process dies by killing all associated running processes including the IDE. The entire process (java class parms) does run just fine if I do it outside my code. So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on. And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path); FileInfo\[\] files = di.GetFiles("\*.xml"); foreach (FileInfo file in files) { Text = "Converting: " + file.Name; String\[\] parms = new String\[1\]; parms\[0\] = file.FullName; ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = @"\\\\NASA\\GSFC\\CDF\\CDFML2CDF.exe"; psi.Arguments = file.FullName; psi.WindowStyle = ProcessWindowStyle.Hidden; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); Text = " Processing successful for file = " + file.Name; Text = " ---- Process output Begin---"; Text = exeProcess.StandardOutput.ReadToEnd(); Text = " ---- Process output End---"; } } catch { Text = " Processing failed for file = " + file.Name; } }
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die. There is nothing logged in the System or application event logs. There is nothing output to the system - IT JUST CRASHES the IDE and Threads. Do you have any helpful ideas or suggestions?
Hi Jerry, I had another idea. If you're using Visual Studio 2010, you can step into the actual .NET framework code that is executing when you call Process.Start(). Just follow these steps: HOW TO: Debug .NET Framework Source[^]
The difficult we do right away... ...the impossible takes slightly longer.
-
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters. Regardless of the above, the Process dies by killing all associated running processes including the IDE. The entire process (java class parms) does run just fine if I do it outside my code. So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on. And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path); FileInfo\[\] files = di.GetFiles("\*.xml"); foreach (FileInfo file in files) { Text = "Converting: " + file.Name; String\[\] parms = new String\[1\]; parms\[0\] = file.FullName; ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = @"\\\\NASA\\GSFC\\CDF\\CDFML2CDF.exe"; psi.Arguments = file.FullName; psi.WindowStyle = ProcessWindowStyle.Hidden; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); Text = " Processing successful for file = " + file.Name; Text = " ---- Process output Begin---"; Text = exeProcess.StandardOutput.ReadToEnd(); Text = " ---- Process output End---"; } } catch { Text = " Processing failed for file = " + file.Name; } }
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die. There is nothing logged in the System or application event logs. There is nothing output to the system - IT JUST CRASHES the IDE and Threads. Do you have any helpful ideas or suggestions?
I would try something like this instead:
psi.StartInfo.FileName=@"c:\javadir\java.exe";
psi.StartInfo.WorkingDirectory = @"\\NASA\GSFC\CDF\";
psi.StartInfo.Arguments=@"CDFML2CDF.exe";
psi.StartInfo.EnvironmentVariables.Add("CLASSPATH", "classpath goes here");Forgive your enemies - it messes with their heads
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters. Regardless of the above, the Process dies by killing all associated running processes including the IDE. The entire process (java class parms) does run just fine if I do it outside my code. So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on. And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path); FileInfo\[\] files = di.GetFiles("\*.xml"); foreach (FileInfo file in files) { Text = "Converting: " + file.Name; String\[\] parms = new String\[1\]; parms\[0\] = file.FullName; ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.FileName = @"\\\\NASA\\GSFC\\CDF\\CDFML2CDF.exe"; psi.Arguments = file.FullName; psi.WindowStyle = ProcessWindowStyle.Hidden; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(psi)) { exeProcess.WaitForExit(); Text = " Processing successful for file = " + file.Name; Text = " ---- Process output Begin---"; Text = exeProcess.StandardOutput.ReadToEnd(); Text = " ---- Process output End---"; } } catch { Text = " Processing failed for file = " + file.Name; } }
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die. There is nothing logged in the System or application event logs. There is nothing output to the system - IT JUST CRASHES the IDE and Threads. Do you have any helpful ideas or suggestions?
Jerry W. Manweiler, Ph.D. wrote:
psi.FileName = @"\\NASA\GSFC\CDF\CDFML2CDF.exe";
That obviously is not java.
Jerry W. Manweiler, Ph.D. wrote:
The IDE and all threads die.
So you run the C# code in an IDE. And with in runs that line the IDE exits. Which is not a crash. Is the IDE Visual Studio? Which version? What happens if you replace the above line with another exe - like notepad (use the full path)?
-
I'm working in .NET 4.0 and there is a Process.Start(ProcessStartInfo) method available. OK if the process is exiting with information what do I need to do to capture that information? The C# code that I'm executing just simply crashes without any exceptions thrown or anything. I am working in the Visual Studio 2010 IDE and it just simply stops.
Jerry W. Manweiler, Ph.D. Fundamental Technologies, LLC
Two suggestions: 1. Display the Exception message (and InnerException message). 2. After it crashes, look at the last entry in the Windows event viewer ([^] )