The PC Guide Discussion Forums  
Google
Web The PC Guide
Studying for the A+, Network+ or Security+ exams? Get over 2,600 pages of FREE study guides at CertiGuide.com!
Join the PC homebuilding revolution! Read the all-new, FREE 200-page online guide: How to Build Your Own PC!
NOTE: Using robot software to mass-download the site degrades the server and is prohibited. See here for more.
Find The PC Guide helpful? Please consider a donation to The PC Guide Tip Jar. Visa/MC/Paypal accepted.

Go Back   The PC Guide Discussion Forums > Special Interest Forums (SIFs) > Programming SIF
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Rate Thread
  #1  
Old 12-07-2006, 10:36 PM
sburtchin sburtchin is offline
Ascendant Master Geek
 
Join Date: Feb 2006
Location: Lost In Middle America
Posts: 307
Parsing Command Line Parameters in DOS Batch Files

I want to develop a batch file to automate creating images using Norton Ghost 2001. Still a rough draft, but here's the relevant code:

Code:
REM Syntax: GHOSTRUN [/cdsplit] [/journal=t] [/nocrc] REM partition [drive][path]fstub [ partition [drive][path]fstub ]... REM REM '/cdsplit' if specified, the image file will be split into 701MB pieces REM REM '/journal=t' if specified, a journal log of type 't' will be created, where REM 't' is "N" (none), "E" (errors), "S" (statistics), "W" (warnings), REM "I" (information), or "A" (all) in inceasing order of detail. REM By default, a log of type "S" will be created. . . . CHECKFORSWITCHES: IF '%1'=='/cdsplit' GOTO SPLITFORCD IF '%1'=='/CDSPLIT' GOTO SPLITFORCD IF '%1'=='/journal=$' GOTO JOURNALTYPE IF '%1'=='/JOURNAL=$' GOTO JOURNALTYPE IF '%1'=='/nocrc' GOTO NOCRC32FILE IF '%1'=='/NOCRC' GOTO NOCRC32FILE GOTO DONECHECKING
How can I parse eg. "/journal=W" to test if this string begins with "/journal"?

How do I extract the "W" from this parameter?

Any help is greatly appreciated. Thanks!
Reply With Quote
  #2  
Old 12-08-2006, 06:50 AM
sburtchin sburtchin is offline
Ascendant Master Geek
 
Join Date: Feb 2006
Location: Lost In Middle America
Posts: 307
Well, here is the first draft (for DOS v7.10). Please check my syntax, especially red text. Thanks.

Code:
@ECHO OFF REM REM Name: GHOSTRUN.BAT (run Norton Ghost to create partition images) REM REM Use this batch file to run Ghost 2001 non-interactively REM to create images of partitions. REM REM REM Syntax: GHOSTRUN [/h|/?] [/cdsplit] [/journal=t] [/nocrc] REM [/dest={drive|path|drive&path}] REM partition filestub [partition filestub]... REM REM '/h' or '/?' If specified, displays the help text. REM REM '/cdsplit' If specified, the image file will be split into 701MB pieces REM REM '/journal=t' If specified, a journal log of type 't' will be created, where REM 't' is "N" (none), "E" (errors), "S" (statistics), "W" (warnings), REM "I" (information), or "A" (all) in inceasing order of detail. REM By default, a log of type "S" will be created. Log types with more REM detail may slow performance, and are not usually necessary. REM REM '/nocrc' If specified, no CRC32 file will be created. REM REM '/dest=' If specified, image files will be created in the location specified. REM by default, images are created in the current directory REM (eg. "/dest=Z:\IMAGES\", "/dest=\", "/dest=IMAGES\"). REM REM 'drive' The DOS drive letter specification (eg. "Z:") REM REM 'path' The DOS path specification (eg. "\", "IMAGES\" "\IMAGES\"). REM NOTE: The trailing "\" is required! REM REM 'partition' Must be in the format "drive#:partition#", where each is specified REM by an integer starting at "1" (eg. "1:3" - 3rd partition on 1st disk) REM REM 'filestub' Is a filename stub (5 characters max). "000.GHO" will be appended REM to this to create the image filename. Other files may be created REM depending on the command line switches. REM REM NOTE: Command line switches may be listed in any order, but MUST preceed the REM 'partition' and 'filestub' parameters! REM REM NOTE: 'partition' and 'filestub' may be repeated as many times as allowed REM by the DOS command line characters limit. REM REM REM REM eg. GHOSTRUN /? {Enter} REM REM eg. GHOSTRUN /cdsplit /dest=z:\images\ 1:3 a26C7 1:11 aA6C2 2:1 b06C5 {Enter} REM REM REM REM Initialize environment variables REM SET SPLITCD=FALSE SET JURNLTYP=S SET CRC32FILE=TRUE SET IMAGETOPATH= REM :CHECKFORSWITCHES IF '%1'=='/h' GOTO DISPINFO IF '%1'=='/H' GOTO DISPINFO IF '%1'=='/?' GOTO DISPINFO IF '%1'=='/cdsplit' GOTO SPLITFORCD IF '%1'=='/CDSPLIT' GOTO SPLITFORCD IF '%1'=='/journal=$' GOTO SETJOURNALTYPE IF '%1'=='/JOURNAL=$' GOTO SETJOURNALTYPE IF '%1'=='/nocrc' GOTO NOCRC32FILE IF '%1'=='/NOCRC' GOTO NOCRC32FILE IF '%1'=='/dest=[drive][path]' GOTO SETIMAGETOPATH IF '%1'=='/DEST=[drive][path]' GOTO SETIMAGETOPATH REM REM Done checking command line for switches REM CLS GOTO BEGIN REM REM :SPLITFORCD SET SPLITCD=TRUE SHIFT GOTO CHECKFORSWITCHES REM REM :SETJOURNALTYPE SET JURNLTYP=?????????????? SHIFT GOTO CHECKFORSWITCHES REM REM :NOCRC32FILE SET CRC32FILE=FALSE SHIFT GOTO CHECKFORSWITCHES REM REM :SETIMAGETOPATH SET IMAGETOPATH=???????????????? SHIFT GOTO CHECKFORSWITCHES REM REM :BADSYNTAX ECHO - ECHO Syntax: GHOSTRUN [/h|/?] [/cdsplit] [/journal=t] [/nocrc] ECHO [/dest={drive|path|drive&path}] ECHO partition filestub [partition filestub]... ECHO - ECHO eg. GHOSTRUN /cdsplit /dest=z:\images\ 1:3 a26C7 1:11 aA6C2 2:1 b06C5 {Enter} ECHO - GOTO END REM REM :DISPINFO ECHO - ECHO Name: GHOSTRUN.BAT (run Norton Ghost to create partition images) ECHO - ECHO Use this batch file to run Ghost 2001 non-interactively ECHO to create images of partitions. ECHO - ECHO - ECHO Syntax: GHOSTRUN [/h|/?] [/cdsplit] [/journal=t] [/nocrc] ECHO [/dest={drive|path|drive&path}] ECHO partition filestub [partition filestub]... ECHO - ECHO '/h' or '/?' If specified, displays the help text. ECHO - ECHO '/cdsplit' If specified, the image file will be split into 701MB pieces ECHO - ECHO '/journal=t' If specified, a journal log of type 't' will be created, where ECHO 't' is "N" (none), "E" (errors), "S" (statistics), "W" (warnings), ECHO "I" (information), or "A" (all) in inceasing order of detail. ECHO By default, a log of type "S" will be created. Log types with more ECHO detail may slow performance, and are not usually necessary. ECHO - ECHO '/nocrc' If specified, no CRC32 file will be created. ECHO - ECHO '/dest=' If specified, image files will be created in the location specified. ECHO by default, images are created in the current directory ECHO (eg. "/dest=Z:\IMAGES\", "/dest=\", "/dest=IMAGES\"). PAUSE ECHO - ECHO 'drive' The DOS drive letter specification (eg. "Z:") ECHO - ECHO 'path' The DOS path specification (eg. "\", "IMAGES\" "\IMAGES\"). ECHO NOTE: The trailing "\" is required! ECHO - ECHO 'partition' Must be in the format "drive#:partition#", where each is specified ECHO by an integer starting at "1" (eg. "1:3" - 3rd partition on 1st disk) ECHO - ECHO 'filestub' Is a filename stub (5 characters max). "000.GHO" will be appended ECHO to this to create the image filename. Other files may be created ECHO depending on the command line switches. ECHO - ECHO NOTE: Command line switches may be listed in any order, but MUST preceed the ECHO 'partition' and 'filestub' paraqmeters! ECHO - ECHO NOTE: 'partition' and 'filestub' may be repeated as many times as allowed ECHO by the DOS command line characters limit. ECHO - ECHO - ECHO - ECHO eg. GHOSTRUN /? {Enter} ECHO - ECHO eg. GHOSTRUN /cdsplit /dest=z:\images\ 1:3 a26C7 1:11 aA6C2 2:1 b06C5 {Enter} ECHO - GOTO END REM REM :ERRORDISPLAY ECHO - ECHO Errors were encountered creating image file %IMAGETOPATH%%2%000.GHO for partition %1. GOTO END REM REM :BEGIN IF '%2'=='' GOTO BADSYNTAX REM SET SPLITSWITCH= SET AUTOSWITCH= IF %SPLITCD% == 'TRUE' SET SPLITSWITCH=-SPLIT=701 IF %SPLITCD% == 'TRUE' SET AUTOSWITCH=-AUTO REM SET CRC32SWITCH= IF %CRC32FILE% == 'TRUE' SET CRC32SWITCH=-FCR=%IMAGETOPATH%%2CRC.TXT REM REM SET ABORTERRORSWITCH=-AFILE=%IMAGETOPATH%%2ERR.TXT REM SET JOURNALSWITCH=-JL:%JURNLTYP%=%IMAGETOPATH%%2%LOG.TXT REM GHOSTPE %SPLITSWITCH% %CRC32SWITCH% %JOURNALSWITCH% %ABORTERRORSWITCH% SRC=%1 DST=%IMAGETOPATH%%2%000.GHO REM REM IF NOT ERRORLEVEL 0 GOTO ERRORDISPLAY ECHO - ECHO Image file %IMAGETOPATH%%2%000.GHO for partition %1 created successfully! REM REM SHIFT SHIFT REM REM IF NOT '%1'=='' GOTO BEGIN REM REM SET SPLITCD= SET JURNLTYP= SET CRC32FILE= SET IMAGETOPATH= SET SPLITSWITCH= SET AUTOSWITCH= SET CRC32SWITCH= SET ABORTERRORSWITCH= SET JOURNALSWITCH= :END
Reply With Quote
  #3  
Old 05-10-2007, 05:38 PM
sortix sortix is offline
Neophyte Geek
 
Join Date: May 2007
Posts: 2
Command Line Parsing Solution

sburtchin...

In looking for the exact same solution you were looking for, i came across a web page that had some code that would help me. Using some of the ideas you had about working through this and the information i found elsewhere, i was able to come up with the following code which will parse through all of the switches on the command line and end when there are no switches left. The big thing here is the delimiter. I used a : as the delimiter and a / as a switch identification. You can made the delimiter whatever you want, but you cant use space, comma, semicolon, equal sign, tab, or carriage return as these are natural DOS delimiters which will give you two input variables.

Hope this helps.

:checkparameters
:: REM Grab the first variable supplied as a whole. Ex. /action:start
set SWITCHPARSE=%1
:: REM Check to see if there are no more switches, if so goto end of
:: parsing, prevents endless loop
IF [%SWITCHPARSE%] == [] goto endswitchparsing
:: REM Reset variables as clean up. Dont know if i need this anymore
:: since i am checking for exit above. Oh well.
set SWITCH=
set VALUE=
:: In the SWITCHPARSE variable, grab the two tokens separated
:: by a : and assign the first to SWITCH and the second to VALUE
for /F "tokens=1,2 delims=: " %%a IN ("%SWITCHPARSE%") DO SET SWITCH=%%a&set VALUE=%%b
:: Check which action to perform based on the switch
IF [%SWITCH%] == [/action] goto setaction
IF [%SWITCH%] == [/servicename] goto setsysservicename
IF [%SWITCH%] == [/servername] goto setservername
IF [%SWITCH%] == [/username] goto setpassedusername
IF [%SWITCH%] == [/userpassword] goto setpasseduserpasswd
:: Perform the action by setting the variable for later use and
:: shift the command line parameters so the next in line is
:: ready to be processed
:setaction
set ACTION=%VALUE%
SHIFT
goto checkparameters

:setsysservicename
set SYSSERVICENAME=%VALUE%
SHIFT
goto checkparameters

:setservername
set SERVERNAME=%VALUE%
SHIFT
goto checkparameters

:setpassedusername
set PASSEDUSERNAME=%VALUE%
SHIFT
goto checkparameters

:setpasseduserpassswd
set PASSEDUSERPASSWD=%VALUE%
SHIFT
goto checkparameters

:endswitchparsing
Reply With Quote
  #4  
Old 05-14-2007, 12:49 AM
sburtchin sburtchin is offline
Ascendant Master Geek
 
Join Date: Feb 2006
Location: Lost In Middle America
Posts: 307
Hi sortix!

First - thanks for posting a solution.

Quite by accident I discovered that the equal sign gets treated the same as a space (at least for my purposes), and I eventually found another solution based upon that. See how I solved here:

Code:
@ECHO OFF REM REM Name: GHOSTRUN.BAT (run Norton Ghost to create partition images) REM REM Use this batch file to run Ghost 2001 non-interactively to create images REM of partitions. The source partition and a five character filename stub are REM required command line arguments. Additional "source partition / filestub" REM pairs may be added as desired as long as the DOS command line limit of 150 REM characters is not exceeded. By default, the following files will be created in REM the current directory: an image file named 'filestub' + "000.GHO", a CRC32 REM check file named 'filestub' + "CRC.TXT", a journal log file of type "S" named REM 'filestub' + "LOG.TXT", and an Abort Error file named 'filestub' + "ERR.TXT" REM if there were errors. If the output is split by use of the "/cdsplit" or REM "/splitcu" switches, additional files will be created named 'filename stub' + REM "001.GHS", 'filename stub' + "002.GHS", etc. "Fast" compression is the default REM for images. Various command line switches may be used to alter the default REM behavior of this batch file. REM REM REM Syntax: GHOSTRUN [/h|/?] [/cdsplit|/splitcu #] [/journal t] REM [/nocrc] [/z #] [/swfile=swfilespec] REM [/dest={drive|path|drive&path}] [/showcmds] REM partition filestub [partition filestub]... REM REM REM Optional Command Line Switches: REM REM '/h' or '/?' Help => If specified, displays the help text. REM REM '/cdsplit' CD Split => If specified, the image file will be split into 701MB REM pieces. REM NOTE: Use of this switch is mutually exclusive with "/splitcu #"! REM REM '/splitcu #' Split Custom, Size => If specified, the image file will be split REM into pieces of the size '#' specified in MiB. REM NOTE: The space is required between "/splitcu" and the size! REM NOTE: Use of this switch is mutually exclusive with "/cdsplit". REM REM '/journal t' Journal, Type => If specified, a journal log of type 't' will be REM created, where 't' is "N" (none), "E" (errors), "S" (statistics), REM "W" (warnings), "I" (information), or "A" (all) in inceasing order REM of detail. By default, a log of type "S" will be created. Log REM types with more detail may slow performance, and are not usually REM necessary. REM NOTE: The space is required between "/journal" and the type code! REM REM '/nocrc' No CRC32 => If specified, no CRC32 file will be created. REM REM '/z #' Compression, Level => If specified, image files will be compressed REM to level '#'. The following values are allowed: "0" (none), REM "1" (Fast), "2" (High), and "3 thru 9" (higher levels). Level "1" REM is the default. REM NOTE: The space is required between "/z" and the level '#'! REM REM '/swfile' Switch File, SwitchFileSpec => If specified, additional command REM line switches as specified in the file 'swfilespec' will be added REM to all Ghost commands. REM REM 'swfilespec' SwitchFileSpec => Any valid DOS file specification. Drive and REM path are optional (eg. "GHSWITCH.TXT"). REM REM '/dest' Destination, Drive&Path => If specified, image files will be REM created in the location specified by 'drive' and/or 'path'. By REM default, images are created in the current directory. REM (eg. "/dest=Z:\IMAGES\", "/dest=Z:", "/dest=IMAGES\", "/dest=\"). REM REM 'drive' Drive => The DOS drive letter specification (eg. "Z:") REM REM 'path' Path => The DOS path specification (eg. "\", "IMAGES\", REM "\IMAGES\"). REM NOTE: When a path is specified, the trailing "\" is required! REM REM '/showcmds' Show Commands => If specified, the Ghost commands will be REM displayed, but not executed. REM REM NOTE: Command line switches may be listed in any order, but MUST preceed the REM 'partition' and 'filestub' parameters! REM REM PAUSE REM Required Command Line Parameters: REM REM 'partition' Must be in the format "drive#:partition#", where each is specified REM by an integer starting at "1" (eg. "1:3" - 3rd partition, 1st disk) REM REM 'filestub' Is a filename stub (5 characters max). "000.GHO" will be appended REM to this to create the image filename. Other files may be created REM depending on the command line switches. REM REM REM NOTE: 'partition' and 'filestub' may be repeated as many times as allowed REM by the DOS command line characters limit. REM REM REM REM eg. GHOSTRUN /? {Enter} REM REM eg. GHOSTRUN /cdsplit /dest=z:\images\ 1:3 a26C7 1:11 aA6C2 2:1 b06C5 {Enter} REM REM REM===================================================================================== rem BEGIN CODE: rem rem Initialize Environment Variables rem SET Split_CD=FALSE SET Journal_Type=S SET CRC32_File=TRUE SET SwitchFile_Sw= SET Image_To_Path= SET Split_Switch= SET Auto_Switch= SET CRC32_Switch= SET Abort_Error_Sw= SET Journal_Switch= SET Compression_Sw=-z1 SET Show_Commands=FALSE rem :CHECKFORSWITCHES IF '%1'=='/h' GOTO DISPINFO IF '%1'=='/H' GOTO DISPINFO IF '%1'=='/?' GOTO DISPINFO IF '%1'=='/cdsplit' GOTO SPLITFORCD IF '%1'=='/CDSPLIT' GOTO SPLITFORCD IF '%1'=='/splitcu' GOTO SPLITCUSTOM IF '%1'=='/SPLITCU' GOTO SPLITCUSTOM IF '%1'=='/journal' GOTO SETJOURNALTYPE IF '%1'=='/JOURNAL' GOTO SETJOURNALTYPE IF '%1'=='/nocrc' GOTO NOCRC32FILE IF '%1'=='/NOCRC' GOTO NOCRC32FILE IF '%1'=='/z' GOTO CUSTCOMPRESSION IF '%1'=='/Z' GOTO CUSTCOMPRESSION IF '%1'=='/swfile' GOTO SETSWFILESWITCH IF '%1'=='/SWFILE' GOTO SETSWFILESWITCH IF '%1'=='/dest' GOTO SETIMAGETOPATH IF '%1'=='/DEST' GOTO SETIMAGETOPATH IF '%1'=='/showcmds' GOTO SETSHOWCMDS IF '%1'=='/SHOWCMDS' GOTO SETSHOWCMDS rem rem Done checking command line for switches rem rem CLS GOTO BEGIN rem rem :SPLITFORCD SET Split_CD=TRUE SET Split_Switch=-SPLIT=701 SET Auto_Switch=-AUTO SHIFT GOTO CHECKFORSWITCHES rem rem :SPLITCUSTOM IF '%Split_CD%' == 'TRUE' GOTO BADSYNTAX SET Split_Switch=-SPLIT=%2 SET Auto_Switch=-AUTO SHIFT SHIFT GOTO CHECKFORSWITCHES rem rem :SETJOURNALTYPE SET Journal_Type=%2 SHIFT SHIFT GOTO CHECKFORSWITCHES rem rem :NOCRC32FILE SET CRC32_File=FALSE SHIFT GOTO CHECKFORSWITCHES rem rem :CUSTCOMPRESSION IF NOT '%2' == '0' SET Compression_Sw=-z%2 IF '%2' == '0' SET Compression_Sw= SHIFT SHIFT GOTO CHECKFORSWITCHES rem rem :SETSWFILESWITCH SET SwitchFile_Sw=@%2 SHIFT SHIFT GOTO CHECKFORSWITCHES rem rem :SETIMAGETOPATH SET Image_To_Path=%2 SHIFT SHIFT GOTO CHECKFORSWITCHES rem rem :SETSHOWCMDS SET Show_Commands=TRUE SHIFT GOTO CHECKFORSWITCHES
I am very interested in learning more about the solution you used. Could you post a link to the web site (or sites) where you found this? Thanks.
Reply With Quote
  #5  
Old 05-16-2007, 11:22 AM
sortix sortix is offline
Neophyte Geek
 
Join Date: May 2007
Posts: 2
Well...what started this whole thing was that I wanted to create a batch file that allowed for parameters to be passed to it. This was pretty easy since all you have to do is pass the parameters and then use %1, %2, %3, etc to use them inside the script. After I started it, I thought why not make it so that the parameters didn’t have to be in a certain order. That is what got me looking into a way to parse the parameters so that the script could determine which parameter was what and assign the parameter value to a variable. The first thing I came across that helped me was your post, mainly your check for switches function and the associated variable assignment functions that utilized the SHIFT command. After reading about the shift command, I realized that I could use that to process each passed parameter until there were no parameters left, in which case you can go to endswitchparsing. I was using -parameter=value but it wasn’t giving me the results I was expecting. Mainly it was treating -parameter as one passed parameter and then value as the next and would repeat this pattern for any remaining variables. I had a hunch that the equals sign was some sort of a natural delimiter.

After a lot of Google searching, I found http://www.robvanderwoude.com/index.html which is a wonderful source of batch scripting knowledge.

At Rob Vanderwoude's web site, if you click on Batch Files on the left and then click on Parameters you will find the information on natural delimiters. As it says space, comma, semicolon, equal sign, tab, and carriage return are natural delimiters for batch file command line parameters. This explained the behavior I was experiencing. I decided not to use a natural delimiter in case I decided to have a parameter passed with no value such as /debug.

Now I had to figure out how to parse the whole value of /switch:value to two separate values of /switch and value. After looking at some code examples, I found the following code:

for /f "tokens=2-4 delims=/ " %%a in ("%DATE%") do (
set dd=%%a
set mm=%%b
set yyyy=%%c)

After running this code, I was intrigued by the results I obtained. The delimiter "/" was discarded and each of the three date values were assigned to the temporary FOR variables of %%a, %%b, and %%c which were then assigned to dd, mm, and yyyy. I found another web site which I can’t locate any longer that explained why this was so. The first %%a is explicit as you state it right in the command. When you use a delimiter and/or tokens, there are implicit variables that start alphabetically after the first explicit variable you use. So in the example above, there is a %%b and a %%c. If there were more results from the date command, then there would be a %%d, %%e, %%f...etc. If you explicitly used %%d in the FOR command, then the next implicit variable is %%e, %%f, %%g...etc. So in my code:

for /F "tokens=1,2 delims=: " %%a IN ("%SWITCHPARSE%") DO SET SWITCH=%%a&set VALUE=%%b

I used the ":" as my delimiter in the command line parameters because I knew that I could split the parameter into two pieces with this FOR statement. Then I used the SWITCH variable to determine which set function to goto and the VALUE variable to set a local variable to the value of the parameter passed.

Hope that makes more sense. I took four Java programming classes in college a couple of years ago which helped me out a lot with the logic behind what I wanted to do.
Reply With Quote
  #6  
Old 05-18-2007, 07:14 AM
sburtchin sburtchin is offline
Ascendant Master Geek
 
Join Date: Feb 2006
Location: Lost In Middle America
Posts: 307
Thanks for the link. No other way to describe that site but - WOW! I found today in my hundreds of poorly organized bookmarks that I had run across that site once before, but somehow it became lost in the dozens of sites vainly attempting to offer help with batch scripting. Until now "/?" has been of more help to me than most of what I found on the web. This one leaves hardly a stone unturned.

As with most programming tasks, there is usually more than one way to skin a cat. In Windows 2000 you can also parse strings using SET. Take a look at this page: DOS Batch File Fun: Creating a subdirectory named after today's date. Beyond fun, a more useful application of this might be to create files that document (within their names) the exact time of their creation, then they are automatically listed in order in Explorer and I don't have to look beyond the filename to know the date. Although intrigueing, I chose not to persue this approach to parsing command line arguments because it does not work in DOS v7 (my GHOSTRUN.BAT is intended to be run from a boot floppy), and it is inherintly more complex than the simple approach of testing the value of one parameter to decide what to do with the next. Parsing with FOR is almost as simple but also fails with older versions of DOS.

I initially conceded to go with for example "/dest" followed by a space and the path like "V:\IMAGES\". Later I discovered by accident (after much wasted time searching the web) that the equal sign gets treated the same as a space. So now I have "/dest=V:\IMAGES\" which looks more DOSlike and less UNIXlike on the command line. I'm still frustrated trying to find explanations of what ALL the special characters (like "=") do on the command line. I see you used "&" to combine two commands on one line.

Quote:
I decided not to use a natural delimiter in case I decided to have a parameter passed with no value such as /debug.
If you ever need a batch file to run in an older version of DOS, see my "/showcmds" switch for an example of a parameter with no value. By testing the parameter first I could then decide if the next parameter should be a value or another parameter.

I spent a couple years working in VMS, among other things, writing batch programs (VMS Command procedures). Almost every OS command in VMS has a "/SHOW" switch you can use to provide a verbatum explanation of what it will do (without "/SHOW"). This lets you tweak the parameters until you have it right so you don't end up with a horrible mess because of a poor choice of parameters. Sadly, I haven't seen this feature with other operating systems. I try to incorporate this feature into my batch programs whenever possible. I also like to add a "/?" switch (echo the header remarks) and do some syntax checking and display some basic syntax rules if a problem is found.

Thanks for explaining the FOR command. That's one I haven't used in a DOS batch file. I'm starting to see a lot of potential for complex string processing.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:06 PM.


Powered by vBulletin Version 3.6.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© Copyright 1997-2004 Charles M. Kozierok. All Rights Reserved.