简体   繁体   中英

Execute commands on windows command prompt from a text file

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

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.

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

Copy "file.txt" tmp.cmd>Nul
Call tmp.cmd && Del tmp.cmd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM