I am making a .bat
file, and I would like it to write ASCII art into a text file.
I was able to find the command to append a new line to the file when echoing text, but when I read that text file, all I see is a layout-sign and not a space. I think it would work by opening that file with Word or even WordPad, but I would like it to work on any computer, even if that computer only has Notepad (which is mostly the case).
How can I open the text file in a certain program (i.e. WordPad) or write a proper space character to the file?
EDIT:
I found that it is the best way to use:
echo <line1> > <filename> echo <line2> >> <filename>
P.S. I used |
in my ASCII art, so it crashed, Dumb Dumb Dumb :)
If so the answer would be simply adding a "." (Dot) directly after the echo with nothing else there. using the >> to direct the output to file will append to the end of the file. If you use a single chevron then the output will overwrite the existing file if it does exist, or create a new file if it does not.
The Windows command prompt (cmd.exe) allows the ^ (Shift + 6) character to be used to indicate line continuation. It can be used both from the normal command prompt (which will actually prompt the user for more input if used) and within a batch file.
To append to a text fileUse the WriteAllText method, specifying the target file and string to be appended and setting the append parameter to True . This example writes the string "This is a test string." to the file named Testfile. txt .
echo Hello, > file.txt echo. >>file.txt echo world >>file.txt
and you can always run:
wordpad file.txt
on any version of Windows.
On Windows 2000 and above you can do:
( echo Hello, & echo. & echo world ) > file.txt
Another way of showing a message for a small amount of text is to create file.vbs containing:
Msgbox "Hello," & vbCrLf & vbCrLf & "world", 0, "Message"
Call it with
cscript /nologo file.vbs
Or use wscript
if you don't need it to wait until they click OK.
The problem with the message you're writing is that the vertical bar (|
) is the "pipe" operator. You'll need to escape it by using ^|
instead of |
.
P.S. it's spelled Pwned.
You can easily append to the end of a file, by using the redirection char twice (>>
).
This will copy source.txt
to destination.txt
, overwriting destination in the process:
type source.txt > destination.txt
This will copy source.txt
to destination.txt
, appending to destination in the process:
type source.txt >> destination.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With