

Doing this way, the process running the command will never ends and you will always get STILLACTIVE when querying GetExitCodeProcess () (meaning the process is still running). A standard C++ program can run without a console window and instead read and write the IO to files, or elsewhere depending on the how the user wants to run it. Then exit /B is not necessary at all in your batch file. :: "C:\ORION\System Information\CoreTemp\64bit\Core Temp. You are passing option /k to cmd.exe, meaning you want the shell to remain active after executing command dir. Run from within a command prompt window cmd / and read the output help explaining the difference on usage of parameter /C (close) which is by default used for batch files and usage of parameter /K (keep) which you should use on running this batch file. To set the ErrorLevel explicitly you could also use cmd /C. The 2> nul portion avoids the message The syntax of the command is incorrect. :: as determined by the "Core Temp" utility at If for /F recieves any STDERR output from the del command line, the command in the loop body is executed, which is set this is an invalid syntax, therefore set sets the ErrorLevel to 1. :: This batch runs if the laptop's Core Temp is close to critical Your parent CMD shell will terminate when the script completes, but the child CMD shell will remain so the window will remain open. You could start a new CMD shell with the /K option within the same window using START /B.

If I want to be able to double click a script and have it run and the window remain open, then I create a shortcut that runs cmd /k "myscript.bat".īut it sounds like you don't want to do either of the above.
#Cmd c exit code#
And the c code dosent give me exception or any notification. The problem is sometimes the application dosent starts up after executing the batch file. cmd /v /e /c' start /high /wait cmd /c launched.cmd & exit errorlevel' Share. I am using following code to write the PATH, EXECUTABLE NAME and ARGUMENTS to a batch file and execute it through CMD using c. but if you need to start the cmd instance to execute the start command that launchs the batch file then you can use. start /high /wait cmd /c BatFileThatReturnsOne.bat.
#Cmd c exit free#
Almost all of the time you will return 1 or true, to indicate the program has closed correctly (ex: might use false if you could not free memory or whatever reason. directly from a cmd window or a batch file you can use. The program will run until you return true or false. Normally I open up a command window first, and then run my batch scripts from there, so my window does not close when the script ends. The program uses int main () to begin and end.
