Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent batch window from closing when error occurs?

Tags:

batch-file

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 
like image 988
Meow Avatar asked Jun 14 '13 23:06

Meow


1 Answers

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.

like image 67
Klitos Kyriacou Avatar answered Oct 06 '22 14:10

Klitos Kyriacou