Does anyone know if its possible to type in a number and get the resulting ASCII characters in a batch file? I think in Unix based machines you type the command then \042 or whatever number you want, but I don't know if you can do it in batch files...

Recommended Answers

All 6 Replies

If your echo accept the -e it would be like:

echo -e "\101"

Otherwise use printf

printf "%b\n" "\0101"

Nope, that only works for bash not batch. Any other ideas?

If there isnt a way, is there a way to define them? Like have a defined as 01 so every time you use 01 it would use a in its place. I don't want to do 26 if statements for the alphabet, or 52 if I make it case sensitive, and adding symbols would be hell, so if I could make definitions some how that would be great.

*Looks Around*
Batch Files Isn't Linux and Unix Shell Scripting.....

No, This isn't possible with command.com / cmd.exe alone (Batch). In order to do it, you will need a special exe of some kind. Easy enough to write one.

deleted

deleted

Does anyone know if its possible to type in a number and get the resulting ASCII characters in a batch file? I think in Unix based machines you type the command then \042 or whatever number you want, but I don't know if you can do it in batch files...

I'm not sure I understand the question exactly.

Are you trying to use a batch file in a Windows environment to send special ASCII characters (000 to 031) to a printer or to a file?

You have already discovered that the echo command can't do that.

I had a problem that required sending the FF (ASCII 012) character to the printer port after printing the output of a DIR command. The FF character was needed to get the printer to push out the last page.

A solution I found was to create a TXT file with only the FF character (FF.TXT) then use the TYPE command to send the file to the printer. Actually, the TXT extension is not necessary but I show it to indicate the file needs to be a text/ascii file to be TYPEd.

DIR [arguments] > PRN
TYPE FF.TXT > PRN

Note that if you use Notepad to create FF.TXT, the file needs to be saved using unicode else the FF character will be stripped from the file.

I'm thinking this approach of using TYPE will work for any special ASCII character you create a special [ASCII].TXT file for.

I'm not sure you are trying to send output to a printer but, if so, you may need to pool your printers so that batch print commands get redirected if your printer is not using LPT1.

If your printer is connected via a USB port you will need a third party driver that allows printing from DOS to a USB printer.

The setup for your printer may provide a driver for printing from DOS programs. Some printer setup programs will allow installing the DOS print option only at time of install so the printer may need to be removed and re-installed to set DOS printing options.

Are you trying to use batch commands to send/append special ASCII characters to a file?

That can be accomplished by concatenating the [ASCII].TXT files created for the special ASCII characters to the file:

COPY /b/y [MAIN].TXT+[ASCII].TXT [MAIN].TXT

The '/b' argument is to copy/concatenate the files in binary. This allows for copying/concatenating the special ASCII characters.

The '/y' suppresses the confirm overwrite prompt. If the destination file name is new there won't be a need for this argument.

If you were looking for a way to write a batch that sent selected special ASCII characters to the standard output where it could be piped where you wanted, there could be multiple TYPE command lines conditioned to TYPE different [ASCII].txt files based on the batch file's parameters.

The TYPE command lines would then not have the redirect '> PRN'.

Be sure that the necessary [ASCII].TXT files are in the same folder as the batch file or that the path for them is in the TYPE command line.

The SHIFT command could be used to process a series of parameters so that you could 'load' the batch file with the codes for the series of ASCII characters you wanted sent.

I know it's kind of messy having to make separate [ASCII].TXT files for each ASCII character you need but this should work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.