Exit codes other than 0 (or EXITFAILURE) indicate the presence of an error in the code.
#Cmd c exit code
The return 0 (or EXITSUCCESS) implies that the code has executed successfully without any error. Where || ensures that the pause command is executed only if dir command fails, and & ensures that a an exit code of 1 is ouput in case of such an error. The purpose of the exit () function is to terminate the execution of a program. If you want the console to remain open if an error occur, you can use the following syntax : CreateProcessA("C:\\Windows\\System32\\cmd.exe","/c dir || pause & exit 1",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi) ::GetExitCodeProcess(pi.hProcess, &dwExitCode) WaitForSingleObject( pi.hProcess, INFINITE ) // wait for process to end If you want to keep the cmd window doesn't close after it is finished, use /K instead of /C: using System.Diagnostics string command 'copy test.txt test2.txt' Process.Start('cmd.exe', '/K. BOOL b = CreateProcess("C:\\Windows\\System32\\cmd.exe","/c dir",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi) Please note the /C before the command line, it means we want cmd to execute the command that follows, and then exit without waiting for any user input. No need to call TerminateProcess() in this case : the dir command return status wil be available from GetExitCodeProcess(). Moreother, you should wait for the process to end using WaitForSingleObject() before querying GetExitCodeProcess(), because CreateProcess() will return immediately after creation of the process (it does not wait for the process to end). If you want the exit code of the dir command, you should use option /c instead (so that cmd.exe ends after executig command dir). Doing this way, the process running the command will never ends and you will always get STILL_ACTIVE when querying GetExitCodeProcess() (meaning the process is still running).
![cmd c exit cmd c exit](http://img.c4learn.com/2012/01/commandline-parameter.jpg)
![cmd c exit cmd c exit](https://content.spiceworksstatic.com/service.community/p/how_to_step_attachments/0000000067/48f7ab80/attached_file/exit.png)
You are passing option /k to cmd.exe, meaning you want the shell to remain active after executing command dir.