Friday, October 21, 2016

Newline character in prompt (or bat files) for Windows 7

So I found a rather old blog post back when I was doing admin stuffs on a Windows 2000 server and XP (which was flashy at the time).
Basically I had a bat file that would "net send" to users that I specified on the network, and to fancy it up a bit I wanted line breaks in the message. It took a few days of research to find the answer and when I did I blogged it. It went something like this :

Wah? Yeah, thought I'd put this information here so I don't loose it! And it took me ages to find this info, so use it wisely.
In cmd prompt (tested on Win2k and WinXP) line you can simulate a return carriage or new line with CTRL-T
If you were to drop into cmd, and type :
net send %computername% "LINE ONELINE TWO"
(replacing by pressing CTRL and T together)
You'll get a pop-up message with 'LINE ONE' on one line and 'LINE TWO' on the next.
ALT-2+0 (hold down ALT and press 2 then 0 on the number pad) does the same thing as CTRL-T
To add this to a batch file use edit.com. It allows you to press CTRL-T.
:monkey:


So yeah, way back when aye. Ok so some character in the post are gone burger (found it on the Wayback Machine as an RSS feed yah!)
This trick no longer works in Windows 7.
However I believe the ALT-010 or ALT-10 works in Windows 8 but I haven't tested because I'm staying away from 8 & 10.

So yeah, on Windows 7 ? Here's the results of my latest research...

set n=^&echo.

Now you can use %n% to output a line feed.

echo Line one%n%Line two

Woah really?

set is used to "set" variables. We are setting "n" to equal "^&echo."

^ is a "ignore first thing after me, or escape the next thingy"

So ^ ignores the &

The & is used to string commands together (like echo hi & echo there)


So the ^ escapes or ignores the & but it's still stringing commands.
You can use ^ to write a string on two multiple line ( look it up :) )
The echo. echos a blank line (you can have lots of different characters after the echo (with no space))


Aiigh are we all clear now?
Good!

If you're writing a bat file drop the

set n=^&echo.

near the top somewhere so you can use %n% all throughout your codey scripty thing.





(yes you may)

No comments: