Reputation: 23
How can I write these characters to file with batch?
Upvotes: 2
Views: 2460
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
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
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