![]() 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. 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 BOOL b = CreateProcess("C:\\Windows\\System32\\cmd.exe","/c dir",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi) Regards the 32bit looking of the cmd pointer: I checked the value of the cmd pointer for a succeeding call. ok Its the same pointer value as the 3rd argument from strace. and then starting it on cmd shell by: > jsshell.bat. cmd 0x14595af0 failed cmd 0x14595af0 Problems calling nvcc jitter: exited, status127 Checking shell. No need to call TerminateProcess() in this case : the dir command return status wil be available from GetExitCodeProcess(). batch file: jsshell.bat: echo off java -jar. To be more explicit about what others have said: Dont think too hard about it. Its not portable, though, the only portable exit values are 0, EXITSUCCESS and EXITFAILURE. I tried to search for 'cmd' in the processes list and to close it (cmdProcess.CloseMainWindow()) but in this case, if I run app. 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). 42 is clearly the opposite of a named value - its a magic value that only the author of the code knows why its there. I have a c app (app.exe), which I want to run from a command line window and then to CLOSE the command line window after the app started. If you opened a command prompt and then ran the batch file, it will not close the parent window when it finishes. 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). If the batch file was launched from a shortcut, 'exit /b' should work fine. ![]() For example the following commands would all set ERRORLEVEL to 0 within your batch-file: VERIFY > nul cmd. Either that or use a command that resets the errorlevel for you, such as echo, findstr etc. Where the number 0 is your wanted errorlevel. 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). in another batch file and call it from your primary script. You are passing option /k to cmd.exe, meaning you want the shell to remain active after executing command dir. I have had the same results with the same two batch files running under Windows XP and Windows 7 Ultimate (64-bit).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |