Thursday, September 30, 2010

Creating a filename using the output of a command in MSDOS

From Microsoft Windows XP Documentation:

Parsing output

You can use the for /F command to parse the output of a command by making the filenameset between the parenthesis a back quoted string. It is treated as a command line, which is passed to a child Cmd.exe and the output is captured into memory and parsed as if it were a file.

For example, a batch file like the one that follows:


@echo off
rem Creates the yyyymmdd.csv file from the statement text file
rem The date for the filename is taken from the statement text file
rem with a perl program called getdate.pl that returns the date throgh
rem standard output
FOR /F "usebackq" %%d IN (`getdate.pl statement.txt`) DO @statement.pl statement.txt > %%d.csv

No comments: