6

I have a question.

How can I execute command in a plain text file?

I know it seems crazy and I can simply rename it as a .bat file BUT it is important for me.
Without renaming it, can i execute it in CMD?

I know I can simply do this :

ren command.txt command.bat & call command.bat & ren command.bat command.txt

But this is too inconvenient. Any simpler way?

Jamie
  • 1,096
  • 2
  • 19
  • 38

2 Answers2

15
cmd < command.txt

Of course it depends of the real content of command.txt.

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Good enough. Didn't thought of that. – Jamie Feb 09 '14 at 11:27
  • You may even execute `if` and `for %a` commands in the text file: http://stackoverflow.com/questions/21242301/running-a-non-bat-extension-file-as-a-batch-file/21248399#21248399 – Aacini Feb 09 '14 at 17:19
0
FOR /F "tokens=*" %%* IN (command.txt) DO %%*
vitsoft
  • 5,515
  • 1
  • 18
  • 31