Computing.Net > Forums > Windows 2000 > Batch File, Variable in File name?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch File, Variable in File name?

Reply to Message Icon

Name: knudsj01
Date: April 5, 2005 at 08:19:21 Pacific
OS: Windows 2000
CPU/Ram: Pentium 3, 256mb Ram
Comment:

Hello,

I'm having a problem with a batch file.
I am trying to use a variable in a filename so that when run the output will go to a time stamped log file.

Here's the type of command I'm trying to run:
ant task-name > C:\logfile%TIME%.log

The error I get is "the parameter is incorrect"



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 5, 2005 at 11:38:59 Pacific
Reply:

Your command likely hides TWO bugs. The first is that reported by the error message probably due to the "-" character in the task-name. I do not know the Ant command, but utilities derived from Unix hates the "-" symbol as it prefixes parameters on the command tail.

So stated %Time% may lead to an error as it contains invalid characters due to the specific county settings as ":"
To analize this problem please type at prompt

Echo Time=%Time%

and report the result so I can suggest the correction needed.


0

Response Number 2
Name: knudsj01
Date: April 5, 2005 at 12:18:18 Pacific
Reply:

Here is what I get: Time=14:17:37.11


0

Response Number 3
Name: IVO
Date: April 6, 2005 at 02:07:53 Pacific
Reply:

Well, as I supposed the Time format is not suited to be part of a PahtName/FileName.
To work around the problem a bit of processing is needed; the following statements tailor the %Time%

Set MyTime=%Time%
Set MyTime=%Mytime:~0,8%
Set MyTime=%MyTime::=-%

as they strip out the secs/100 and replace the ":" with "-".

So you have to log to C:\logfile%MyTime%.log

So stated the first question is still with no answer: is what I said about the Ant command correct? As the batch interpreter never went to parse the logfile's name.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Word 2k3 clipart issue User Profile



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Batch File, Variable in File name?

Batch file variables in Win2000/NT www.computing.net/answers/windows-2000/batch-file-variables-in-win2000nt/18378.html

Batch file Query www.computing.net/answers/windows-2000/batch-file-query/63285.html

text file editting in a batch file www.computing.net/answers/windows-2000/text-file-editting-in-a-batch-file/31251.html