Questions on switches and child shells

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Questions on switches and child shells

#1 Post by TNTBlast » 04 Apr 2012 17:29

I just started learning DOS today and I have been using this http://www.allenware.com/icsw/icswidx.htm as my guide. However there are several things that confuse me. When starting on lesson 2 http://www.allenware.com/icsw/icsw020.htm I found that the command "command /z /k" wouldn't create a new child shell that allowed me debug my program, and that the command "command /y /c" would not let me do a step by step debugging.

So my question is why don't any of these work? Is it because it was written for windows 98 and xp, and if this is the case is there a new better way to do what they are suggesting?

On another note I was wondering if there is anywhere where I can find a list of the switches used in DOS because I would like some better definitions.

Thank you.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Questions on switches and child shells

#2 Post by abc0502 » 04 Apr 2012 18:30

tryied "command.com /?" in dos window it came up with switches but ther is no such /K switch try it.

TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Re: Questions on switches and child shells

#3 Post by TNTBlast » 04 Apr 2012 19:36

I did the same, but it does do what they said it does, but is there even a reason to do what they are asking or is it unnecessary?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Questions on switches and child shells

#4 Post by abc0502 » 04 Apr 2012 19:42

sorry i'm confused :roll: with your question what are u using command for?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Questions on switches and child shells

#5 Post by Ed Dyreen » 04 Apr 2012 19:43

'
Hi TNTBlast, I learned batch using the same site, a lot has been added since :D

My advise, don't use command.COM unless you grew up with it ( you won't need it ).
The modern command line interpreter is cmd.EXE.

This will let you debug your batches

Code: Select all

start "CMD" %comspec% /k "Hello world !.CMD" /arguments

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Questions on switches and child shells

#6 Post by Liviu » 04 Apr 2012 19:51

TNTBlast wrote:I just started learning DOS today and I have been using this http://www.allenware.com/icsw/icswidx.htm as my guide.

Unless you really mean "DOS" as in "16-bit MS-DOS", I wouldn't recommend that particular tutorial. On the page you linked, it is clearly stated that it's for (the DOS based) Windows 9x/ME. Incidentally, there is also a clickable popup labeled "NT/2000/XP" towards the top of the page, which answers your direct questions: there is no /z "return-code" nor /y "debug-mode" in CMD.EXE.

Since it looks like you've found this forum ;-) note that the dostips site itself has quite a few other pages and links which might get you started in the right direction.

Liviu

TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Re: Questions on switches and child shells

#7 Post by TNTBlast » 04 Apr 2012 19:55

Thank you for your responses I understand now.

Ed could you please elaborate on what the code you just posted means (especially the /k switch)?
Liviu which resource from dostips would be the best to start at?
Last edited by TNTBlast on 04 Apr 2012 20:01, edited 1 time in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Questions on switches and child shells

#8 Post by Ed Dyreen » 04 Apr 2012 20:00

'
Hello world !.CMD

Code: Select all

@echo off &cls
echo.
echo.%~n0
echo.
echo. Uses the /k switch to prevent crashes,
echo. I use it to debug my batch files ;)
echo.
pause
cmd /?
pause
exit 0
debug_Hello world !.CMD

Code: Select all

@echo off &start "CMD" %comspec% /k "%~dp0\Hello world !.CMD" /arguments

TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Re: Questions on switches and child shells

#9 Post by TNTBlast » 04 Apr 2012 20:09

Sorry ed but could you make your post more clear?

1)First how does /k prevent crashes and what does it do specifically?
2)What does /arguments mean? Is it a comment you are making or a command?
3)What does "%~dp0\" mean?
4)How does this debug specifically?

Thank you.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Questions on switches and child shells

#10 Post by Liviu » 04 Apr 2012 21:03

TNTBlast wrote:Liviu which resource from dostips would be the best to start at?

"Best" is in the eye of the beholder ;-) Much depends on your learning style, and purpose why you decided to learn it. Guess you could start at "my first batch file", or "script snippets" linked off the main page. Or find a batch file close to what you want to accomplish, make sure you first follow what it's doing, then start toying with it and watch what happens. Sometimes it's quite insightful to break a working thing, and understand why it stopped working. All said, there is no single "best" advice.

Liviu

P.S. As for the /k switch, run "cmd /?" at a command prompt, and it will tell you that it "carries out the command specified by string but remains". Most commands display their own help when run with "/?". Among the better documented I'd count "cmd", "set", "call", "if", "for".

TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Re: Questions on switches and child shells

#11 Post by TNTBlast » 05 Apr 2012 03:43

So is there any other way to create a child shell that will return the error level of everything you do? (Look here to see what I mean http://www.allenware.com/icsw/icsw020.htm it's in the middle of the page)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Questions on switches and child shells

#12 Post by foxidrive » 05 Apr 2012 05:21

You can have a doskey macro to execute this:

echo %errorlevel%

TNTBlast
Posts: 6
Joined: 04 Apr 2012 17:15

Re: Questions on switches and child shells

#13 Post by TNTBlast » 05 Apr 2012 06:05

Alright I think I'm fine now.

Thank you everyone who replied :D

Post Reply