views:

35

answers:

3

Hi guys, i have a perl script that is used in updating my awstats logs of my website. The script works fine if i just paste it in cmd (Windows) but the moment i paste it in a batch file, it messes up the format of the files generated (they should be prepended with current date/time). The code is:

perl C:\PROGRA~2\AWStats\tools\awstats_buildstaticpages.pl -config=mywebsite -update -awstatsprog=C:\PROGRA~2\AWStats\wwwroot\cgi-bin\awstats.pl -dir=C:\myfolder\stats\reports -builddate=%YYYY%MM -buildpdf=C:\PROGRA~2\HTMLDOC\ghtmldoc.exe -staticlinksext=asp`

The resulting files generated is mysite.201008.asp if i paste it in cmd and execute BUT In a batch file with the same script, my resulting file is mysite.MM.asp.

Any idea why this is happening?

A: 

It appears you have to escape the '%' characters.

Thomas Langston
so it should be `...-builddate=\%YYYY\%MM` if i wanted it to work?
sch-55
@sch-55: no, see atzz's answer
ysth
+4  A: 

The problem is caused by %YYYY%MM.

"%" is a special symbol in batch files. You need to escape it by doubling it: %%YYYY%%MM.

atzz
I tried it and it works perfectly! Thank you very much atzz and all other guys who chipped in to help :)
sch-55
A: 

The command shell doing variable substitution on %YYYY% which I'm guessing is not defined in your environment, so it substitutes the empty string for that "variable".

Unfortunately, there are no opaque quotes in the Windows shell.

Axeman