0

My text file has all the commands written down that have to be executed(one command on each line). How do I request the windows command prompt to read each command from this text file and execute it? I did try to research on this problem and the solution that I got was using batch files. I do not know what are batch files. Please help.

All the ten commands in the text file are:

tesseract.exe 1.png ../newfile/1 -l eng
tesseract.exe 2.png ../newfile/2 -l eng
tesseract.exe 3.png ../newfile/3 -l eng
tesseract.exe 4.png ../newfile/4 -l eng
tesseract.exe 5.png ../newfile/5 -l eng
tesseract.exe 6.png ../newfile/6 -l eng
tesseract.exe 7.png ../newfile/7 -l eng
tesseract.exe 8.png ../newfile/8 -l eng
tesseract.exe 9.png ../newfile/9 -l eng
tesseract.exe 10.png ../newfile/10 -l eng
Zirak Mistry
  • 15
  • 2
  • 6

2 Answers2

0

You could do it in a for loop.

For /f "delims=" %%i in (filename.txt) do "%%i"

It basically loops through the file. delims= changes standard delimiters being whitespace, so it grabs the entire line instead.

To create the batch file. Open notepad.exe and add the above code. Save the file in the same directory as your text file as some name and add a extension of .cmd

Alternatively, you can just rename the current text file to an extension of .cmd and run it.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
0

As mentioned at the foot of Gerhard's answer, you could use Rename:

Copy "file.txt" tmp.cmd>Nul
Call tmp.cmd && Del tmp.cmd
Compo
  • 36,585
  • 5
  • 27
  • 39