在批处理文件中运行 perl 脚本

发布于 2024-09-16 17:53:55 字数 577 浏览 7 评论 0原文

我有一个 perl 脚本,用于更新我网站的 awstats 日志。如果我只是将其粘贴到 cmd (Windows) 中,该脚本可以正常工作,但是当我将其粘贴到批处理文件中时,它会弄乱生成的文件的格式(它们应该在前面加上当前日期/时间)。代码是:

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`

如果我将其粘贴到cmd中并执行,生成的结果文件是mysite.201008.asp,但是在具有相同脚本的批处理文件中,我生成的文件是mysite.MM< /strong>.asp。

知道为什么会发生这种情况吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃兔兔 2024-09-23 17:53:55

该问题是由 %YYYY%MM 引起的。

“%”是批处理文件中的特殊符号。您需要通过加倍它来转义它:%%YYYY%%MM

The problem is caused by %YYYY%MM.

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

愛放△進行李 2024-09-23 17:53:55

看来您必须转义“%”字符。

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

硬不硬你别怂 2024-09-23 17:53:55

命令 shell 在 %YYYY% 上进行变量替换,我猜您的环境中没有定义它,因此它用空字符串替换该“变量”。

不幸的是,Windows shell 中没有不透明的引号。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文