LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get status returned by the last process

Solved!
Go to solution

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.

0 Kudos
Message 1 of 15
(5,425 Views)

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,

0 Kudos
Message 2 of 15
(5,396 Views)

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).

0 Kudos
Message 3 of 15
(5,396 Views)
Solution
Accepted by mdokic

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,

S. Eren BALCI
IMESTEK
Message 4 of 15
(5,389 Views)

Thanks for the info. Looks like that is what I'll have to do.

0 Kudos
Message 5 of 15
(5,286 Views)

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!

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 15
(5,278 Views)

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.

0 Kudos
Message 7 of 15
(4,017 Views)

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

0 Kudos
Message 8 of 15
(4,011 Views)

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.

0 Kudos
Message 9 of 15
(4,004 Views)

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.

Message 10 of 15
(4,000 Views)