07-23-2009 09:15 AM
I'm debugging a call to the systme exec.vi and would like some clarification.
LV 6.1, windows XP
I have a custom .NET executable that is called by the system exec.vi with some options. I created a .bat that calls my application perfectly from windows. When the .bat file is run using system exec.vi the called application crashed. Debugging showed that if the bat file was modified to include "start" my application ran (but I couldn't get the return code). Several versions of debug code later we found that my application crashed as it called clear (the clear console command.)
Removing the clear command from my application solved the issue. but WHY?
07-23-2009 10:26 AM
07-23-2009 11:33 AM - edited 07-23-2009 11:35 AM
smercurio_fc wrote:
Presumably the .NET app is a console application? correct
What is the command that you're providing to the System Exec function? Are you including "cmd /k" at the beginning?
c:\folder_name\function.bat
Bat file = c:\folder_name\executable.exe Param1 Param2
Also tried passing c:\folder_name\executable.exe Param1 Param2 directly to the system exec.vi
the application crashed both ways and it was tracked down to occur at the clear console call in the exe by modifying the source code.
the App did not crash when called with a preceding "Start " or when the batch file was run from windows. However, I NEEDED the return code so, this was merely a trouble shooting clue.
the question remains though WHY did the app crash when called from the system exec.vi and not crash otherwise?
07-23-2009 08:26 PM
I'm not sure why the Clear() method would crash, and not a method like WriteLine(). One thing you have to keep in mind is that System Exec is more like the Start->Run comman, so it doesn't create a console to begin with.
You could try the technique I had posted here and launch a command window and paste the command you want to run (the last message in the thread has an example of this).
07-24-2009 07:57 AM
Thanks for the tip Smercurio!
I think I figured out the why in the shower this morning. See if this makes sense or if I should have used more hot water......
So I launch system exec.vi with wait for completion true. System exec.vi grabs a handle on the console window so it can update its stdout parameter when the app completes. The app also grabs that same handle so the updates can be made. If the app selects the Clear() method the system tries to reinitialize the console which would make the handle held by system exec.vi invalid or stale so the system prevents the Clear() method and returns an execption to the app. The app sees this event and says (basically-in non geek speek) "So I can't even control the console I own? OK, then have a nice day and Blank-you (but not the horse you rode in on cuz' that's cruel)." Finally the system hears the grumbling from the app (unhandled exception) and takes its own action to put the unruly, PO'd app on the time-out chair. Or to put it back in geek speek. "The app has encountered an error and needs to close"
Seems like a reasonable explaination and accounts for the observations and effective work-arounds discussed in related threads. Am I close?
07-24-2009 10:21 AM
07-24-2009 10:25 AM
smercurio_fc wrote:
Sorry. Don't know that much about the inner workings of Microsoft software on that kind of operation, and when I really think about it I don't think I want to know.
You don't sound too sorry. Thanks