Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have 3 problems:</p> <p>1) You don't exit your program after the main loop so it falls through into the subroutine</p> <p>2) Your FOR /L IN() clause is wrong, the first number should be 1, not 2</p> <p>3) You need to reset T back to undefined within the outer loop.</p> <p><em><strong>EDIT</em></strong><br/> I believe you may have an additional problem. When redirecting output you prefix your file name with <code>%cd%</code>. I don't think that is giving the result you want. If your current directory is <code>C:\test</code>, then <code>&gt;&gt;%cd%see.log</code> will result in output sent to file named <code>testsee.log</code> in the root <code>C:\</code> directory. If you wanted the output in the current directory then it should be <code>&gt;&gt;%cd%\see.log</code>, but the path info is not really needed since the default is to use the current directory. So really all you would need is <code>&gt;&gt;see.log</code>. Since I don't know your intent, I have left the redirection as originally written. <strong><em>End Edit</em></strong></p> <pre><code>@echo Off SetLocal EnableDelayedExpansion SET mydir=D:\ SET DirCount=2 For /F %%i In (qqq.txt) Do ( SET T= set fg=%%i FOR /L %%G IN (1, 1, %DirCount%) DO (call :subroutine "%%i") ) exit /b :subroutine Set T=!T!../ start /wait %mydir%program.exe %T%%fg% echo %t%%fg% &gt;&gt;%cd%see.log </code></pre> <p>There is no need to call a subroutine in your case, especially since you have already enabled delayed expansion. The following gives the same result with less code, and it is faster because it avoids the relatively slow CALL statement. <em>(performance is probably not an issue in this small example, but if using loops with many iterations it can make a huge difference)</em></p> <pre><code>@echo Off SetLocal EnableDelayedExpansion SET mydir=D:\ SET DirCount=2 For /F %%i In (qqq.txt) Do ( SET "T=" FOR /L %%G IN (1, 1, %DirCount%) DO ( set "T=!T!../" start /wait %mydir%program.exe !T!%%i echo !T!%%i &gt;&gt;%cd%see.log ) ) </code></pre> <p><br/><strong><em>Partial answer to additional questions</em></strong></p> <p>You can use FOR /F to capture the result of FIND /C to get the number of lines in "qqq.txt". This should be done before you enter the main loop:</p> <pre><code>for /f %%N in ('find /c /v "" ^&lt;qqq.txt') do set "rowCount=%%N" </code></pre> <p>You can use SET /A to do basic math, thus enabling you to keep track of the number of remaining lines</p> <p>First initialize the remaining count before entering the main loop:</p> <pre><code>set "remainingLines=%rowCount%" </code></pre> <p>Then within the main loop use SET /A to decrement the value.</p> <pre><code>set /a remainingLines-=1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload