|
One more note, in case I didn't explain well enough. The part that really added difficulty for me was the ability to add multiple delimiters to each octet so that I could say
192.168.0.1
<no 193="">
194.168.0.1
195.168.0.1
196.168.0.1
by entering 192,194-196.168.0.1
This is valid input for nmap, but I don't know of any other application that will parse it correctly.
Nmap uses about 600 lines of C code to accomplish it. I'm curious if C# would be more or less. My bet is less.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Hi,
I am trying to calculate the duration between two dates in days. But it seems it is calculating always 1 less than the actual duration. I am not understanding is it a bug from MS or something. Following is the code to calculate it.
If you feel its correct one then can you please help me calculating the duration depending on the small date time in instead of calculating the date time on full date time.
string pendDuration = string.Empty;
if (pendActivityDetail.PostponeDate.HasValue)
{
pendDuration = pendActivityDetail.PostponeDate.Value.Subtract(pendActivity.ActivityDateTime).Days.ToString();
}
return pendDuration;
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
If I run this:
DateTime dt1 = new DateTime(2011, 11, 12);
DateTime dt2 = new DateTime(2011, 11, 13);
DateTime dt3 = new DateTime(2011, 11, 14);
DateTime dt4 = new DateTime(2011, 11, 15);
Console.WriteLine(dt4.Subtract(dt4).Days);
Console.WriteLine(dt4.Subtract(dt3).Days);
Console.WriteLine(dt4.Subtract(dt2).Days);
Console.WriteLine(dt4.Subtract(dt1).Days);
I get exactly what I expect:
0
1
2
3 So where do you think it is making a mistake? What values are you using, and what are you expecting?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: So where do you think it is I am making a mistake?
you are testing at midnight only. The surprises come in when the times are different.
|
|
|
|
|
You might be looking for the TimeSpan.TotalDays[^] property.
The Days property only gives you the day component of the time span... For example:
3 days, 23 hours, 59 minutes, 59 seconds:
... Days = 3, Hours = 23, Minutes = 59, Seconds = 59
... TotalDays = ~3.999, which you can round to 4
|
|
|
|
|
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
|
|
|
|