07-30-2014 10:48 AM
I am using LaunchExecutableEx to launch Java executable. Once this processs terminates it returns a value. How can I get that value? GetLastError ( ) does not work.
Solved! Go to Solution.
07-31-2014 01:33 PM
Hi,
You should be able to read the error code into an integer variable as follows:
Int myErrorCode = LaunchExecutableEx(myFilename, myState, &myHandle);
To get a better understanding of what the error codes mean, take a look at the following help documentation:
http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvilaunchexecutableex/
Regards,
07-31-2014 02:11 PM
I tried that but it always returns zero. I think this represents that the process was successfully executed, not the status of the process upon exit. The process will return 0 if it succeeded it's operation or 1 or 2 if it failed. If I execute it from a command line and type %ERRORLEVEL% I can see that it failed (2).
08-01-2014 12:09 AM
Hi,
I also occasionally call other executables from my CVI programs.
Best method of getting data out of them is to direct their output to a file and then to read and parse the file.
"myOtherExe.exe >out.txt" directs an executables output to file rather than standart output window.
After executables has terminated you can read the file to get information about its status.
Regards,
08-11-2014 05:57 PM
Thanks for the info. Looks like that is what I'll have to do.
08-12-2014 05:31 AM
I am glad it solved your problem.
Please mark the reply as a solution, so it can be seen by anyone browsing the forum.
Thanks!
11-19-2015 11:08 AM
Great solution, ebalci. This will work for me as well. I can also get the external executable's run status this way by parsing the output file for success/failure.
But what about incremental running status? In my case, my executable is a MCU programmer. It's output looks like this, if run to STDOUT:
Erasing the target chip. Writing to program memory. Writing 000000h Writing 001000h Writing 002000h Writing 003000h Writing 004000h Writing 005000h Writing to ID and other locations. No errors. Elapsed time was 29.2 seconds.
Those "Writing" lines happen incrementally, i.e., you can see it working real time.
The problem with piping to a file is that this all gets written to the file and then afterword, CVI reads it. So CVI doesn't have visibility of its running status.
Is there a different piping method (accessible bufffer), to which I could attach a callback function in CVI? Then I could get a sense of running time of my executable.
11-19-2015 11:43 AM
Could it be a possible solution to periodically check the properties of this file, e.g., file size or time last modified? If this value changes CVI could read the file again...
Just an idea without having it tried myself
11-19-2015 01:21 PM
Yeah that could work. I can't seem to find CVI libraries that deal with file properties though. This thread claims there are such, but doesn't name them.
11-19-2015 02:55 PM
In the toolbox there is a function called FileExists ( path_name, &file_size ) which returns the size of the file in bytes (if it exists). You could also consider GetFileTime ( file_handle, &hours, &minutes, &seconds ); from the Utility library which returns the time the file was last modified.