LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the errorlevel of a DOS Command Line programm in a CVI App

Hi

I have to start a DOS Command Line Programm from my CVI App with
LaunchExecutable() or System(). The DOS Programm ends with its state
(OK, NotOk, ...) returned to the shell. How can I read this error
state in the CVI App ???
I'm using CVI 5.5.
Thanks
Oliver
0 Kudos
Message 1 of 4
(4,029 Views)
Sorry, can't do it, not with those functions. You would have to use Windows SDK programming. I think the function CreateProcessEx in the SDK is what you would want to use.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(4,029 Views)
I found an example of how to do it with SDK programming. It's shown below. This example runs the process, waits for it to finish, then checks the exit code. It assumes an exit code of 0 is success.


static int RunBatchFile (char *path)
{
PROCESS_INFORMATION pInfo;
STARTUPINFO sInfo;
int success = FALSE, exitCode, cursor;

cursor = GetWaitCursorState();
SetWaitCursor (1);

memset (&sInfo, 0, sizeof (sInfo));
sInfo.wShowWindow = LE_SHOWNORMAL;
sInfo.dwFlags = STARTF_USESHOWWINDOW;
sInfo.cb = sizeof (sInfo);

if (CreateProcess (NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo) == 0)
goto Error;

if (WaitForSingleObject (pInfo.hProcess, 6 * 60 * 60 * 1000) != WAIT_OBJECT_0) // 6 hour timeout
goto Error;


GetExitCodeProcess (pInfo.hProcess, &exitCode);
if (exitCode != 0) // assumes that these batch files return 0 on success
goto Error;

success = TRUE;

Error:
SetWaitCursor (cursor);
if (pInfo.hProcess)
CloseHandle (pInfo.hProcess);

return success;
}
0 Kudos
Message 3 of 4
(4,029 Views)
It works fine that way..
Thanks a lot
Oliver
0 Kudos
Message 4 of 4
(4,029 Views)