This is a dumping ground of software development topics that I've run across and found interesting (mainly .NET development). Many topics are covered more thoroughly in other places, and much of the information is gleaned from other places, and I'll try to credit those sources when possible.

Friday, February 08, 2008

Getting a Batch File's Command Line

I can't remember where I got this batch script, but it's handy for getting the complete command used to call the batch file. For instance, the text written to the file may be something like this: "C:\cmdlinetest.bat" -install -param2 some other stuff...
-------------------------------------------------------------------------

REM Set variable 'line' to first token in the command line.
set line=%0

REM Loop through the next token, concatenating value, then shifting the
REM command line to process the next token. Stop when token is empty.
:loop
set line=%line% %1
if "%1" == "" goto :done
shift
goto loop

REM Done finding command line arguments, echo to file.
:done
echo %line% > C:\cmdline.txt

Followers