|
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");
|
|
|
|
|
What does it do ? Try using
bool isChecked = (string)reader["var"] == 1;
checkBox.Checked = isChecked;
and putting a breakpoint on checkBox.Checked and see what value isChecked comes up with.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thanks for your patience. This piece of code has worked successfuly
int result = Convert.ToInt32((string)reader["var"]);
if(result == 1)
checkBox.Checked = true
|
|
|
|
|
Hi All,
I am calling a c++ dll from C# application. with out name mangling how can i call c++ function and class from c# application?
Thanks in advance.
G.Paulraj
|
|
|
|
|
You are going to have to use Interop(System.Runtime.Interopservices).Something to the tune of :-
[Dllimport("your dll")]
public static extern void functionName(parameters);
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hi... thanks for ur quick reply.
in .h file i have declared like
__declspec(dllexport) char* BaseClassFunction();
in .CPP file the definition is like
extern "C" __declspec(dllexport) char* __stdcall ISim::BaseClassFunction()
{
static char* pszCPUType = "derived class function called";
return pszCPUType;
}
from c# i am calling like following...
const String _dllLocation1 = @"D:\Project\Dll.dll";
[DllImport(_dllLocation1)]
static extern String BaseClassFunction();
String Baseclass = BaseClassFunction();
MessageBox.Show(Baseclass.ToString());
the above code is not working...
any help will be appricated..
G.Paulraj
|
|
|
|
|
Paulraj G wrote: the above code is not working.
That is not a very helpful piece of information; exactly what is not working; does the program crash, do you see the wrong results, etc.?
You have defined a DLL function as
extern "C" __declspec(dllexport) char* __stdcall ISim::BaseClassFunction()
and I suspect the ISim:: prefix may be affecting your exported name; you can check with Dependency Walker[^]. Also I am not sure whether a char* returned from C++ will be accepted as a String in C#, you should check the PInvoke rules for marshalling, and also this article[^], and this one[^], by Luc Pattyn[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi - Think it's easier just look at the following code fragment than me attempting to explain this. But basically, Regex.Split isn't splitting the source string way I've expected.
Following example try to split the string at "Timestamp" locations - example "hh:mmPM EST"
<br />
static void TestRegularExpressionSplit()<br />
{<br />
string Src = "467.00 9:32PM EST 467.32 9:33PM EST 468.18 9:34PM EST ";<br />
string SplitExpr = @"([0-9]{1,2}[:]{1}[0-9]{1,2}(PM\sEST){1})";<br />
Regex Expr = new Regex(SplitExpr);<br />
string[] Tokens = Expr.Split(Src);<br />
return;<br />
}<br />
Expected:
467.00
9:32PM EST
467.32
9:33PM EST
468.18
9:34PM EST
Actual:
467.00
9:32PM EST
PM EST
467.32
9:33PM EST
PM EST
468.18
9:34PM EST
PM EST
REF: http://msdn.microsoft.com/en-us/library/ze12yx1d.aspx
dev
|
|
|
|
|
Your MSDN reference says: If capturing parentheses are used in a Regex.Split expression, any captured text is included in the resulting string array.
So, strip those extra capturing parentheses from your regex - you don't need them. You can also simplify it a bit, to something like
string SplitExpr = @"([0-9]{1,2}:[0-9]{1,2}PM\sEST)"; Note I haven't checked this, but it should get you headed in the right direction. You may need to play with the odd \s somewhere to get exactly what you want.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|