Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anything after DOS FOR /F loop not executing

I've had a jolly good search through the world of google to find a similar problem to mine, but I can't find any examples of people doing things outside of their FOR /F loops and so I am resigned to creating a new thread.

I am using a FOR /F loop to execute a Ruby Gem once per line it finds in a reference file, which it does perfectly. The problem is, when it has finished scrolling through its reference file and executed the Ruby Gem the correct amount of times, it will not complete anything else in the .CMD file outside of the FOR /F loop.

Here is my .CMD code:

FOR /F "tokens=1,2,3 delims=," %%a in (c:\cygwin\usr\work\easy.lst) do (
c:\ruby191\bin\scrapitalist website -u http://www.website.com/%%a/%%c/%%b.html -o     C:\cygwin\usr\autobets\work\%%b_%%c.easy
)
copy c:\cygwin\usr\work\*.easy c:\cygwin\usr\autobets\work\easy.imp

The easy.lst file has two lines of data in it.

The loop works fine, executing the Ruby Gem and creating *.easy files as output, however, the COPY command never executes. I can replace the copy with an ECHO, or in fact anything, but it will not execute.

I cannot see what I am missing from my FOR /F syntax - any ideas peeps?

Thanks

like image 735
user1458484 Avatar asked Jun 15 '12 11:06

user1458484


People also ask

What does%% mean in dos?

Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file.

What are tokens in cmd?

FOR /F processing of a text file consists of reading the file, one line of text at a time and then breaking the line up into individual items of data called 'tokens'. The DO command is then executed with the parameter(s) set to the token(s) found.

How do I stop a loop in CMD?

To stop this infinite loop, press Ctrl + C and then press y and then Enter.


1 Answers

I suppose that scrapitalist is a batch file itself, therefore it stops the batch file, but as the FOR-loop is cached, it work to the end.

To solve this you only need a single call as prefix.

FOR /F "tokens=1,2,3 delims=," %%a in (c:\cygwin\usr\work\easy.lst) do (
  call c:\ruby191\bin\scrapitalist website -u http://www.website.com/%%a/%%c/%%b.html -o     C:\cygwin\usr\autobets\work\%%b_%%c.easy
)
copy c:\cygwin\usr\work\*.easy c:\cygwin\usr\autobets\work\easy.imp
like image 50
jeb Avatar answered Oct 16 '22 21:10

jeb