Write console text to a file (Windows cmd.exe)
Wednesday, March 26th, 2008Writing directly from the Windows command line to a file might not be something you need to do very often. The famous black and white console is better suited to serving system commands and file operations than being a stand-in for notepad. However, it is sometimes useful to have the option of writing multiple lines of text to a file directly from the trusty prompt.
Method One
This is suitable for creating/overwriting a file with multiple lines of text.
copy con SOME_FILE.txt
Type your text here
You can even have multiple lines!
When finished, press CTRL+Z to confirm your action (or CTRL+C to cancel) and ENTER.
If you want to append some text instead of overwriting it completely, follow as above but using:
copy SOME_FILE.txt + con
Method Two
Open up the command prompt and type:
echo SOME TEXT > SOME_FILE.txt
This method creates/overwrites SOME_FILE.txt with the text you entered before the >. It is only suitable for entering a single line of text into a file.
As with method one, it possible to append text using >> instead of > in the command.