Windows 批处理脚本:For ... in 循环捕获程序输出不起作用
我有一个批处理脚本设置来自动从远程 FTP 服务器检索文件。部分要求是每天使用新的日期戳来命名该文件,例如“File_90611.csv”。我有一个可以生成文件名的命令行工具;然后应该使用下面的行将其设置为变量:
for /f "delims=" %a in ('C:\BIN\YesterdayDateStamp.exe') do @set DATESTAMP=%a
问题是这样的。直接从命令行运行时,此行工作正常。但是,当我将完全相同的行放入批处理脚本并运行它时;我收到此错误:
\BIN\YesterdayDateStamp.exe') 此时是意外的。
我删除了脚本中除 FOR ... IN 命令之外的所有内容,以确保不存在某种冲突;但即使如此我仍然收到错误。
一直在谷歌搜索答案,但没有线索。有什么想法吗?非常感谢任何建设性的意见。
谢谢, 坦率
I have a batch script setup to automatically retrieve a file from a remote FTP server. Part of the requirement is the file will be named with a new datestamp each day, such as "File_90611.csv." I have a command line tool that generates the filename; which is then supposed to be set to a variable using the line below:
for /f "delims=" %a in ('C:\BIN\YesterdayDateStamp.exe') do @set DATESTAMP=%a
The problem is this. This line works fine when run from the command line directly. However, when I put this exact same line in a batch script and run it; I get this error:
\BIN\YesterdayDateStamp.exe') was unexpected at this time.
I REM'ed everything out in the script except the FOR ... IN commands to make sure there wasn't some sort of conflict; but even with this I still get an error.
Been Googling for an answer but have no leads. Any ideas? Any constructive input is greatly appreciated.
Thanks,
Frank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在批处理文件中使用
for
时,需要将变量名前面的百分号加倍。来自
for /?
:When
for
is used in a batch file, you need to double the percent signs in front of the variable name.From
for /?
: