How to prevent batch window from closing when error occurs?

I'm trying to write batch script to create a folder if it does not already exist. Following up the online examples, below is my script.

The problem is; first pause works, then probably due to syntax error the window closes even before reaches to the second pause, so I can't really tell which part of my script is wrong.

Could anyone show me how to prevent closing window so that I can see what's on the window?

@echo off

:copy theme images over
:designer
echo copying theme images over...
pause
if not exist "%K2DIR%\K2 SmartForms Runtime\Styles\Themes\Sharepoint 2013\rich_text"
(
    md "%K2DIR%\K2 SmartForms Runtime\Styles\Themes\Sharepoint 2013\rich_text333"
)

pause

Solution 1:

You could put this line at the beginning of the batch file:

if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )

What this line does is, the first time you run it, it re-launches itself in a subprocess that doesn't exit after it finishes running the batch file.

Solution 2:

You need to pass the /K switch to CMD, or just open a Command Window and run the batch from the command line.