Capturing CMD batch file parameter list; write to file for later processing

cmdparametersvariables

I have written a batch file that is launched as a post processing utility by a program. The batch file reads ~24 parameters supplied by the calling program, stores them into variables, and then writes them to various text files.

Since the max input variable in CMD is %9, it's necessary to use the 'shift' command to repeatedly read and store these individually to named variables. Because the program outputs several similar batch files, the result is opening several CMD windows sequentially, assigning variables and writing data files. This ties up the calling program for too long.

It occurs to me that I could free up the calling program much faster if maybe there's a way to write a very simple batch file that can write all the command parameters to a text file, where I can process them later. Basically, just grab the parameter list, write it and done.

Q: Is there some way to treat an entire series of parameter data as one big text string and write it to one big variable… and then echo the whole big thing to one text file? Then later read the string into %n variables when there's no program waiting to resume?

Parameter list is something like 25 – 30 words, less than 200 characters.

Sample parameter list:
"First Name" "Lastname" "123 Steet Name Way" "Cityname" ST 12345 1004968 06/01/2010 "Firstname+Lastname" 101738 "On Account" 20.67 xy-1z 1 8.95 3.00 1.39 0 0 239 8.95

Items in quotes are processed as string variables. List is space delimited.

Any suggestions?

Best Answer

echo %* 1>args.txt

%* references all arguments: %1 %2 %3...

It also works with subroutines.

call :test 1 2 3
goto :eof

:test
echo 1: %1
echo 2: %2
echo 3: %3
echo *: %*
exit /b

output:

1: 1
2: 2
3: 3
*: 1 2 3

See the following website for more information: http://ss64.com/nt/syntax-args.html

Related Topic