Thursday, September 17, 2009

How to make %date% compatible in DOS shell?

I have to create a shell script running in a DOS command on Windows 2003 Server. I need to log a time stamp as text string and parse it. Thanks google, I found a solution like this.

However, the output of DOS command echo %date% looks not compatible between 2 Windows 2003 server: it's Thu 09/17/2009 on one box and 09/17/2009 Thu on another one.

Finally I figured out a CHCP command should be called to set the active code page number. It's usage is:

CHCP [nnn]

nnn Specifies a code page number.
Type CHCP without a parameter to display the active code page number.

A test result is:
in code page 437, the output will be Thu 09/17/2009
in code page 936, the output will be 09/17/2009 Thu

So we know the trick now... :)

No comments: