Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I echo ASCII art that contains special characters in a batch file?

Tags:

So.. This is (to me anyway) the most important feature of this program. I need this to work. Please don't laugh.. (okay you can laugh) but when my program errors, I want it to display this:

          _ _,---._         ,-','       `-.___        /-;'               `._       /\/          ._   _,'o \      ( /\       _,--'\,','"`. )       |\      ,'o     \'    //\       |      \        /   ,--'""`-.       :       \_    _/ ,-'         `-._        \        `--'  /                )         `.  \`._    ,'     ________,','           .--`     ,'  ,--` __\___,;'            \`.,-- ,' ,`_)--'  /`.,'             \( ;  | | )      (`-/               `--'| |)       |-/                 | | |        | |                 | | |,.,-.   | |_                 | `./ /   )---`  )                _|  /    ,',   ,-'               ,'|_(    /-<._,' |--,               |    `--'---.     \/ \               |          / \    /\  \             ,-^---._     |  \  /  \  \          ,-'        \----'   \/    \--`.         /            \              \   \  

Echoing each line doesn't work...

echo              _ _,---._  echo           ,-','       `-.___  echo          /-;'               `._  echo         /\/          ._   _,'o \  echo        ( /\       _,--'\,','"`. )  echo         |\      ,'o     \'    //\  echo         |      \        /   ,--'""`-.  echo         :       \_    _/ ,-'         `-._  echo          \        `--'  /                )  echo           `.  \`._    ,'     ________,','  echo             .--`     ,'  ,--` __\___,;'  echo              \`.,-- ,' ,`_)--'  /`.,'  echo               \( ;  | | )      (`-/  echo                 `--'| |)       |-/  echo                   | | |        | |  echo                   | | |,.,-.   | |_  echo                   | `./ /   )---`  )  echo                  _|  /    ,',   ,-'  echo                 ,'|_(    /-<._,' |--,  echo                 |    `--'---.     \/ \  echo                 |          / \    /\  \  echo               ,-^---._     |  \  /  \  \  echo            ,-'        \----'   \/    \--`.  echo           /            \              \   \  

I'm assuming this is because of the symbols in the text. Any way to fix it? Or do I need to give up on the "DOH" screen?

like image 265
user2863294 Avatar asked Oct 28 '13 18:10

user2863294


People also ask

How do I make a batch file echo?

To create a Windows batch file, follow these steps: Open a text file, such as a Notepad or WordPad document. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause. Save your file with the file extension BAT, for example, test.

What does @echo off do in a batch file?

To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.


1 Answers

Include the following in your script:

::: :::              _ _,---._ :::           ,-','       `-.___ :::          /-;'               `._ :::         /\/          ._   _,'o \ :::        ( /\       _,--'\,','"`. ) :::         |\      ,'o     \'    //\ :::         |      \        /   ,--'""`-. :::         :       \_    _/ ,-'         `-._ :::          \        `--'  /                ) :::           `.  \`._    ,'     ________,',' :::             .--`     ,'  ,--` __\___,;' :::              \`.,-- ,' ,`_)--'  /`.,' :::               \( ;  | | )      (`-/ :::                 `--'| |)       |-/ :::                   | | |        | | :::                   | | |,.,-.   | |_ :::                   | `./ /   )---`  ) :::                  _|  /    ,',   ,-' :::                 ,'|_(    /-<._,' |--, :::                 |    `--'---.     \/ \ :::                 |          / \    /\  \ :::               ,-^---._     |  \  /  \  \ :::            ,-'        \----'   \/    \--`. :::           /            \              \   \ :::  for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A 

The image could be placed anywhere within the script. It does not need to be near the FOR statement. I chose ::: as a distinguishing label for each image line because : is used for normal labels, and :: is frequently used as a comment.

2014-10-22 Update

There is an even simpler solution using my REPL.BAT utility - a hybrid JScript/batch script that performs a regex search/replace on stdin and writes the result to stdout. Simply substitute the following line for the FOR statement above:

call repl "^:::" "" a <"%~f0" 

REPL.BAT is pure script that will run on any Windows machine from XP onward. Full documentation is embedded within the script. This solution uses the A option to only print lines that were altered.

like image 139
dbenham Avatar answered Oct 24 '22 05:10

dbenham