How to start multiple sub cmd.exe shells without getting lost

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

How to start multiple sub cmd.exe shells without getting lost

#1 Post by jfl » 04 Sep 2017 06:55

For testing new experimental batch files, it is often wise to start a sub-shell within your cmd shell.
This way, if your batch file fails and trashes your environment, you can simply return to the clean environment by typing "exit".
Also, you might want to test the script from within environments with variable expansion enabled or disabled, etc.

If you're like me and have several cmd shell windows open, and multiple sub-shells open within each, like russian dolls, it is very easy to get lost and not remember which shell is which.

Here comes subcmd.bat. A very simple script that changes the cmd prompt, to display the russian doll index, and the extension and expansion modes.

Ex:

Code: Select all

C:\JFL\Temp>subcmd

#2 E:on V:off C:\JFL\Temp>set "X=1"

#2 E:on V:off C:\JFL\Temp>subcmd /V:on

#3 E:on V:on C:\JFL\Temp>set "X=2"

#3 E:on V:on C:\JFL\Temp>subcmd /E:off

#4 E:off V:on C:\JFL\Temp>set "X=3"
The syntax of the command is incorrect.

#4 E:off V:on C:\JFL\Temp>set X=3

#4 E:off V:on C:\JFL\Temp>exit

#3 E:on V:on C:\JFL\Temp>echo !X!
2

#3 E:on V:on C:\JFL\Temp>exit

#2 E:on V:off C:\JFL\Temp>echo !X!
!X!

#2 E:on V:off C:\JFL\Temp>echo %X%
1

#2 E:on V:off C:\JFL\Temp>exit

C:\JFL\Temp>echo %X%
%X%

C:\JFL\Temp>

Available there:
https://github.com/JFLarvoire/SysToolsL ... subcmd.bat
Run subcmd /? to get a help message with a list of options.

Enjoy!

Jean-François

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to start multiple sub cmd.exe shells without getting lost

#2 Post by aGerman » 04 Sep 2017 09:57

I indeed like that much because I often run my batch files from within a cmd prompt. Especially for debugging reasons. Thanks for sharing, Jean-François!

Steffen

Post Reply