Handles the return value of the console app execution at the command line. Create a new Win32 Console project: The Comparedirs code is as follows (VS2008 code generated by default):
1 //CompareDirs.cpp: Defines the entry point of the console application. 2 // 3 4#include"stdafx.h" 5#include"CompareDirs.h" 6 7 #ifdef _DEBUG8 #defineNew Debug_new9 #endif Ten One A //the only Application object - - CWinApp Theapp; the - using namespacestd; - - int_tmain (intARGC, tchar* argv[], tchar*envp[]) + { - intnRetCode =0; + A //initializing MFC and displaying errors on Failure at if(! AfxWinInit (:: GetModuleHandle (NULL), NULL,:: GetCommandLine (),0)) - { - //TODO: Change the error code to suit your needs -_tprintf (_t ("Error: MFC initialization failed \ n")); -nRetCode =1; - } in Else - { to //TODO: Write code here for the behavior of the application. + } - the returnnRetCode; *}
The return value of the CompareDirs.exe to be processed from the command line. Looked up on the internet, there is processing is not correct, there are processing LOG instead of the return value. Modify the different return values of the CompareDirs.exe to verify the output of the batch program execution.
@echo off comparedirs @if "%errorlevel%" = = "0" goto good : Fail echo (execution Failed) Echo ( return value =%errorlevel%) goto end : Good Echo (execution succeeded) echo (return value =%errorlevel %) goto end : End Pause
To handle the return value of the console app execution at the command line