views:

3958

answers:

4

Hello, and thank you for reading.

I'm making a .bat file and i'd like it to write ASCII-Art into a txt 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 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(wich is mostly the case).

Can someone help me figure out how to open the text file in a certain program (i.e. WordPad) or how to write a proper space character to the file?


EDIT:

Ty all, awesome site and realy fast answers! 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 :)

+7  A: 
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.

Mark
Ty!I didn't realise that that adds a line!Awesome :)
billyy
yeah i noticed that i could do that but im trying to keep it compact you see, just create the file, else it would just copy it :)But theres no way to do that with only using write 1 time now is there?
billyy
Is english your first language?
Will
@Mark: Dude, would you like a laugh? You edited this question just after I did, I nearly had heart failure when I saw "edited . . . Mark " , my name is also Mark and I sat here sputtering "But but but HOW DOES IT KNOW MY NAME!!!". It wasn't having fun there for a minute :)
Binary Worrier
Damn, there's too many of us!
Mark
@will: I guess it is. Most people who learned it as a secondary language usually pay more attention to detail.
Tomalak
No, will i'm dutch/italian and pour english is pretty good for my kind $.$ And Mark, ty a lot for the great comment, it was realy usefull! :)
billyy
np, you're welcome
Mark
+3  A: 

You can easily append to the end of a file, by using the redirection char twice e.g. Instead of

type source.txt > Destination.Txt

which will copy source to destination, overwriting destination in the process, you can

type source.txt >> Destination.Txt

which will append to destination

Binary Worrier
indeed tough, i just want it to create the file, not copy..<br>else i could just make it open a file withotu creating it first, but i think its better to have it as compact as posible.
billyy
+2  A: 

Maybe this is what you want?

echo foo > test.txt
echo. >> test.txt
echo bar >> test.txt

results in the following within test.txt:

foo

bar

Will
yeah i think it would be the best way to do this, i might edit the file to make a command that will split it up in parts...<br>at least, ill try ;)
billyy
+1  A: 

echo "text to echo" > file.txt

Jeff Leonard
that would just (optonally)create a command, write a line on it.. but it wouldnt make a next line ;)
billyy