48

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 :)

billyy
  • 2,265
  • 3
  • 18
  • 13
  • 1
    I'm afraid the question needs serious reformulation and a few input/output/code samples. You've lost ma about half way through... – Tomalak Apr 21 '09 at 17:10
  • 1
    wow, you're everywhere. Its hard to understand what you're asking. Try to ask a clear question in as few lines as possible. Also, a sample containing what you are doing now would help. –  Apr 21 '09 at 17:10
  • 1
    "Tough when it writes to a txt file i just see a layout-sign not a space" That hurt my head. –  Apr 21 '09 at 17:12

6 Answers6

91
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
  • 6,269
  • 2
  • 35
  • 34
  • Ty! I didn't realise that that adds a line! Awesome :) – billyy Apr 21 '09 at 17:12
  • 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 Apr 21 '09 at 17:14
  • 1
    There should be a **bold warning** saying that `>` overwrites entire file content :) – Adelin May 21 '18 at 08:05
13

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
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Binary Worrier
  • 50,774
  • 20
  • 136
  • 184
  • indeed tough, i just want it to create the file, not copy..
    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 Apr 21 '09 at 17:17
12

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

  • 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...
    at least, ill try ;)
    – billyy Apr 21 '09 at 17:19
2

Use the following:

echo (text here) >> (name here).txt

Ex. echo my name is jeff >> test.txt

test.txt

my name is jeff

You can use it in a script too.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
ItzYeBoi
  • 31
  • 1
2
echo "text to echo" > file.txt
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Jeff Leonard
  • 3,284
  • 7
  • 29
  • 27
  • that would just (optonally)create a command, write a line on it.. but it wouldnt make a next line ;) – billyy Apr 21 '09 at 17:21
1
  • I always use copy con to write text, It so easy to write a long text
  • Example:

    C:\COPY CON [drive:][path][File name]

    .... Content

    F6

    1 file(s) is copied

pc43
  • 439
  • 1
  • 7
  • 19