开发者

Windows Batch Script: For ... in loop to capture program output not working

开发者 https://www.devze.com 2023-04-03 19:49 出处:网络
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, 开发者_StackOverflow中文版such a

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, 开发者_StackOverflow中文版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


When for is used in a batch file, you need to double the percent signs in front of the variable name.

From for /?:

To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号