Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS Batch-How CMD file use input from another files content 1

Status
Not open for further replies.

tekinfarmland

Technical User
May 22, 2002
20
US
I am on a windows 2003 server, trying to write a dos batch script.
I have a file with a date in it "date.txt"
content looks like "Thu Mar 29 12:27:36 2012"

I have another file copy.cmd that has 5 input parms corresponding to the 5 date parts above %1 is for "day", %2 is for "month", %3 is for "date", %4 is for "time", and %5 is for "year"

How can I feed the content of the date.txt file in 5 pieces as parameters to the copy.cmd? "copy.cmd < date.txt" does not work.

Is there a windows resource kit tool, another tool, or a way to do that command to do what I want without writing a control program to parse the date and call copy.cmd with the date pieces as parms?
 
Well, you seem to be wanting to do this at script launch time.

If you really want to do that from a command line:
Code:
for /f "tokens=1,2,3,4,5" %a in (c:\date.txt) do c:\dateme.bat %a %b %c %d %e

Or you could just run the batch file and read it in as it runs:
Code:
@echo off
setlocal

for /f "tokens=1,2,3,4,5" %%a in (c:\date.txt) do @set zDay=%%a&& set zMonth=%%b&& set zdate=%%c&& set ztime=%%d&& set zyear=%%e

echo I pulled in the following parameters:
echo Day   = %zday%
echo Month = %zmonth%
echo Date  = %zdate%
echo Time  = %ztime%
echo Year  = %zyear%
pause

Or, as you said you don't want a control or wrapper you could run the script almost as you've said you'd tried: "copy.cmd date.txt". i.e. without the < redirect, but instead just with the date.txt filename as a parameter. This code shows how to pull in the content of the date.txt file:
Code:
@echo off
setlocal

set datefile=%1
if not defined datefile goto NoDateFile
if not exist %datefile% goto DateFileNotFound
goto main

:DateFileNotFound
	echo. Datefile "%datefile%" not found. Quitting
	echo. Press any key to continue . . .
	goto eof

:NoDateFile
	echo. No datefile provided. Quitting
	echo. Press any key to continue . . .
	goto eof

:main
	for /f "tokens=1,2,3,4,5" %%a in (%datefile%) do @set zDay=%%a&& set zMonth=%%b&& set zdate=%%c&& set ztime=%%d&& set zyear=%%e

	echo I found following parameters in %datefile%:
	echo Day   = %zday%
	echo Month = %zmonth%
	echo Date  = %zdate%
	echo Time  = %ztime%
	echo Year  = %zyear%
	pause

:eof
	pause>nul

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top