Tech Support > Operating Systems > MS-DOS > Syntax for escape characters
Syntax for escape characters
Posted by Nathan Sokalski on January 15th, 2005


I want to use certain special characters such as the <backspace> character
in command lines. I need to know how to enter this in command prompt and
other places that command lines are used. Any help would be appreciated.
Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
www.nathansokalski.com


Posted by Norman L. DeForest on January 15th, 2005



On Sat, 15 Jan 2005, Nathan Sokalski wrote:

Assuming you use COMMAND.COM (which is appropriate for the alt.msdos.batch
newsgroup), I can only thing of two ways:

1. Get 4DOS and use it instead of COMMAND.COM. (If you use a Windows NT
based version of Windows with CMD.EXE, then alt.msdos.batch is the
wrong newsgroup and alt.msdos.batch.nt is the correct group.) At
the 4DOS prompt, type Alt-255 (press and hold down the Alt key, type
"255" using the number-pad keys, and then release the Alt key)
followed by the control character you want to use. The control
character will be inserted into the command-line.

2. Enter the characters into a batch file and run the batch file.
If you don't have a text-editor that allows you to enter control
characters, there are two ways to get them into a batch file.
(a) Get a text-editor that *does* allow the entry of control
characters. One such text editor is Tiny Editor from PC Magazine.
Both the original version and some patched, enhanced versions
are available from links on my Computer Tips page at:
http://www.chebucto.ns.ca/~af380/Tips.html#TinyEd
A full-screen text editor in only about 3000 bytes (yes, that's
bytes and not kilobytes or megabytes).
(b) Get and use my "Super Echo" command, EKKO.COM
http://www.chebucto.ns.ca/~af380/Tips.html#Tip011
to echo the command you want to a batch file and then call
the batch file. Say you want to execute

echo Get rid of Outhouse^H^H^H^H^Hlook Express.

where "^H" represents a backspace character. You could use:

ekko echo off$_echo Get rid of Outhouse$r5.$x08.look Express.$, >foo.bat
call foo

or, if your command *is* an echo command, just use EKKO:

ekko Get rid of Outhouse$r5.$x08.look Express.

"$r" starts a repeat loop. "5" is the count, "." is used as a
delimiter (almost any non-digit can be used ("$" is an exception)),
"$x08" prints a backspace character, and "." (the delimiter again)
ends the repeat loop. That's shorter than "$x08$x08$x08$x08$x08".
If you need an Escape character (Esc key or Control-[), you can
use "$e" (just as with prompt) to echo ANSI escape sequences:

ekko $e[33;45m A colourful "Hi!" $e[37;40m

--
Norman De Forest http://www.chebucto.ns.ca/~af380/Profile.html
af380@chebucto.ns.ca [=||=] (A Speech Friendly Site)
My Usenet 2005 calendar: http://www.chebucto.ns.ca/~af380/Year-2005.txt
For explanation: http://www.chebucto.ns.ca/~af380/Links.Books.html#TandD


Posted by Todd Vargo on January 15th, 2005



"Nathan Sokalski" <njsokalski@verizon.net> wrote in message
news:nn3Gd.1169$rs2.23@trndny07...
This really depends on what you intend to do with the special characters. On
one hand, sure you can type special characters into your batch, but that
does not necessisarily mean those characters will do what you expect.

Using backspace for example, sure you can type backspace characters using
your editor. But if you expected to display them on screen as a thick black
bar with lights using ECHO statements, forget it. The backspace function
overrides display of the character. If you expected to use the backspace to
remove characters from variables, forget it. The actual effect would be to
append the backspace characters to the variable.

--
Todd Vargo (double "L" to reply by email)


Posted by Nathan Sokalski on January 16th, 2005


I understand that you can type the special characters, and that typing them
does not always do what you want. That is why I need to know the escape
sequence (a series of characters that is interpreted as the special
character). In my case, I want to append the backspace character to the end
of an existing file in order to remove the last character.
--
Nathan Sokalski
njsokalski@hotmail.com
www.nathansokalski.com

"Todd Vargo" <toddvargo@alvantage.com> wrote in message
news:34u848F4ebt3oU1@individual.net...


Posted by foxidrive on January 16th, 2005


On Sun, 16 Jan 2005 05:13:21 GMT, Nathan Sokalski wrote:

That will merely add an extra character to the end of the file.

Here's something which removes the last two bytes, though testing here
indicates that changing the 02 to an 01 makes it remove only the last byte.

:: based upon a batch by Tom Lavedas
@echo off
if "%1"=="" echo Syntax: %0 Sourcefile
if "%1"=="" echo Purpose: Removes trailing two bytes (CR/LF usually)
if "%1"=="" goto end
type nul>temp.txt
for %%v in (E100''83''E9''02 L103 P N%1 W103 Q) do echo %%v>>temp.txt
if exist %1 debug %1 <temp.txt >nul
del temp.txt
:end


Posted by Todd Vargo on January 16th, 2005



"Nathan Sokalski" <njsokalski@verizon.net> wrote in message
news:RJmGd.5706$qu2.2779@trndny08...
So actually, you want to truncate a character from a file, not append a
backspace to it. Escape sequences do not apply to what you want to do. Since
you crossposted this to groups intended for different OSes, you
necessisarily should indicate which OS you will actually be doing this in.
Some hint as to the file sizes likely to be dealt with would be good too.

Also, since the people who will likely answer your question already read all
three groups, you don't need to further crosspost to these groups.

--
Todd Vargo (double "L" to reply by email)


Posted by Nathan Sokalski on January 16th, 2005


That's great, but would you mind explaining the following 2 lines to me?
Whenever I use code from a newsgroup, I like to know what it's doing before
I use it:

for %%v in (E100''83''E9''02 L103 P N%1 W103 Q) do echo %%v>>temp.txt
if exist %1 debug %1 <temp.txt >nul

Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
www.nathansokalski.com

"foxidrive" <micm@melbpc.org.au.invalid> wrote in message
news:gts5jurlhlll.ostv2q8yxkgv$.dlg@40tude.net...


Posted by Matthias Tacke on January 16th, 2005


Nathan Sokalski wrote:
That code is fed into debug and means

E100 enter hex from adrress 100
83 E9 02 is in assembler opcode SUB CX,02
which means decrease the file length by 2.
L103 reload the file passed to debug at address 103
P Execute one command from address 100
N%1 Name the file (again)
W103 write to named file from address 103 (with decreased size)
Q Quit debug.

IIRC that will work for file sizes below 2^16 = 65536 bytes

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+


Similar Posts