output to file in a DOS for loop

September 6, 2009 at 12:28:58
Specs: DOS, old
Hi,

I'm trying to write a command for DOS command prompt that will call an executable and save the results to a text file. So I want to achieve this:

myExec dataFile.1 > dataOut1.txt
myExec dataFile.2 > dataOut2.txt
... (each of these individually already works fine)

I tried writing a for loop like this:

for %A in (1 2 3) do myExec dataFile.%A > dataOut%A.txt

The problem is that the ">" output to file thing gets interpreted as applying to the for loop, not to each command - so the end result is that myExec gets called but doesn't save the .txt file, except for the last one which saves to a file literally called "dataOut%A.txt".

I tried putting the whole "myExec... > ..." part in quotes which let to it knowing the correct commands but not executing them (not explaining that well, but anyway it didn't work).

Thanks so much for any help!!

Nick


See More: output to file in a DOS for loop

Report •


#1
September 6, 2009 at 12:53:46
try:
for /l %A in (1,1,3) do myExec dataFile.%A > dataOut%A.txt

if running from a batch:
for /l %%A in (1,1,3) do myExec dataFile.%%A > dataOut%%A.txt


Report •

#2
September 6, 2009 at 13:04:35
I get a "Syntax error" when I try that...

Is the flag "/L" or lowercase L or capital i or what? I tried all of those but if it's supposed to be something else, maybe that's what I'm doing wrong.

Also, I'm using old-school for-real boot-up DOS, not a DOS prompt in windows or whatever. I'm not sure if that makes a difference. Thanks,

Nick


Report •

#3
September 6, 2009 at 15:14:50
I haven't used true MS-DOS for a long time, but I think you
have to do this:

Main batch file:
for %%A in (1 2 3) do call doMyExec.bat %%A

Auxiliary batch file doMyExec.bat:
myExec dataFile.%1 > dataOut%1.txt

So it's easier just to do this:
myExec dataFile.1 > dataOut1.txt
myExec dataFile.2 > dataOut2.txt
myExec dataFile.3 > dataOut3.txt


Report •

Related Solutions

#4
September 6, 2009 at 21:35:18
There is no for /f nor for /L in DOS.

Try klint's method.


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question