somedude
somedude

Reputation: 23

Write special charaters with batch into file

How can I write these characters to file with batch?

enter image description here

Upvotes: 2

Views: 2460

Answers (3)

Zero Degres
Zero Degres

Reputation: 29

You cannot handle or display a nul char in the console, you 'll have to work directly with binary stream. In batch it's limited to the command type, > and >>.

What you can do is create a file with a null char inside, and write it into a file with the command >> regarding your need :

Ex :

:: Creating the file with the null char inside
if not exist FileWithANulCharInside.txt (fsutil file createnew FileWithANulCharInside.txt 1)
:: Adding it into a dummy file
>test.log (0<nul set /p=abc)
>>test.log type FileWithANulCharInside.txt
>>test.log (0<nul set /p=abc)
pause

Source : http://johnfender.fr/?p=1138

Upvotes: 0

jeb
jeb

Reputation: 82202

You can echo nearly all characters with batch, but not NUL.
batch chr function

You could use Jscript (also a batch/jscript hybrid is possible).
In Jscript there is a simple chr() function

Upvotes: 1

nitro2k01
nitro2k01

Reputation: 7745

I quick search suggests that ^ can be used to escape certain special characters. Not sure whether it will work for the characters you mentioned, but perhaps worth a try.

http://www.robvanderwoude.com/escapechars.php

Upvotes: 0

Related Questions