Run a Text File as a Batch Script
Yes this is possible by making the text file which contains the commands you need executed to be referenced as the first batch argument that is passed to the batch script.
You can set the argument value as a variable and using type you can create a temporary batch file with the content of the text file and then run that file through cmd to process accordingly.
Batch Script Logic
@ECHO ON
SET cmdtxt=%~1
SET cName=%~N1
if exist "%tmp%\%cName%.cmd" del /q /f "%tmp%\%cName%.cmd"
if not exist "%tmp%\%cName%.cmd" type "%cmdtxt%" >> "%tmp%\%cName%.cmd"
cmd /k "%tmp%\%cName%.cmd"
pause
exit
Note: You can use cmd /c to have the command window(s) close after execution.
Text File
ECHO Line 1
dir *.txt
Note: This is the text file without a .bat
or .cmd
which each line will contain a valid batch command which will be executed.
Execute this by using either. . .
1.Drag and Drop
2. Command Line
C:\Users\User\Desktop\RunMe\RunTextCommands.cmd "C:\Users\User\Desktop\RunMe\cmd.txt"
@ECHO OFF
Results
Further Resources