|
To start with your definition is not precise.
A timestamp consists of a date and a time.
So you MUST define exactly what values you expect with the following values.
2011-07-28 14:37:38 and 2011-08-28 14:37:38
2011-07-28 14:37:38 and 2011-08-28 14:37:37
2011-07-28 14:37:38 and 2011-08-28 14:37:39
Other variations might be important as well.
And if your timestamps have a daylight savings time component then you must define that as well.
|
|
|
|
|
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
|
|
|
|
|
Please Wrap your code in "pre" Tag to give better readability to other users.
|
|
|
|
|
The process is not exiting without any information, you are just not capturing it.
I'm not sure what version you are using but the Process class doesn't have a static Start method, or one that returns a Process object that I can find.
using(Process p = new Process())
{
try
{
p.StartInfo = psi;
if(p.Start())
{
p.WaitForExit();
}
else
{
}
}
catch(Exception ex)
{
}
}
Also note the use of pre tags to format code snippets when posted.
No comment
modified 29-Nov-11 14:49pm.
|
|
|
|
|
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
|
|
|
|
|
Indeed, I missed the overloaded method in the docs.
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
|
|
|
|
|
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
|
|
|
|
|
Two suggestions:
1. Display the Exception message (and InnerException message).
2. After it crashes, look at the last entry in the Windows event viewer ([^] )
modified 2-Dec-11 15:01pm.
|
|
|
|
|
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
{
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.
Fundamental Technologies, LLC
|
|
|
|
|
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.
|
|
|
|
|
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 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");
|
|
|
|
|
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 have a collection like this:
Products
|_Categories
|_Parts
Using Linq-To-SQL, I need to update specific parts in the collection based on the part_number property. I'm not sure of this to write this. Could use some help.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
What have you tried so far? What resources have you looked at?
With Linq2SQL you have an entity object that represents your database table. All you need to do is update the property you want then save the changes within the scope of your DataContext. There are many resources here and elsewhere that cover Linq2Sql and will explain in greater detail
No comment
|
|
|
|
|
hi, I have got some some check boxes which I want to check or uncheck based on values retrieved from database. I tried soething but it did not work. Here is what I tried.
string variable = (string)reader["var"];
if (variable.Equals("1"))
{
checkbox.Checked = true;
}
what can I do? thnx
|
|
|
|
|
If field "var" in the database is always an integer, you could do something like this:-
checkBox.Checked = (int)reader["var"] == 1 ? true : false;
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
or simpler without the ternary operator:
checkBox.Checked = (int)reader["var"] == 1;
|
|
|
|
|
That too
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Well the data type is nchar(20) in sql server, though the data is numeric.
|
|
|
|
|
In that case a direct cast to int will throw an exception. If you require all true values to equal "1" then you could just do this :-
checkBox.Checked = (string)reader["var"] == "1";
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
It is not working. Here is what I tried
checkBox.Checked = ((string)reader["var"] == "1");
|
|
|
|