Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a null ASCII character (nul) to a file with a Windows batch script?

I'm attempting to write an ASCII null character (nul) to a file from a Windows batch script without success. I initially tried using echo like this:

echo <Alt+2+5+6>

which seems like it should work (typing <Alt+2+5+6> in the command window does write a null character - or ^@ as it appears), but echo then outputs:

More?

and hangs until I press <Return>. As an alternative I tried using:

copy con tmp.txt >nul
<Alt+2+5+6><Ctrl+Z>

which does exactly what I need, but only if I type it manually in the command window. If I run it from a batch file it hangs until I press <Ctrl+Z> but even then the output file is created but remains empty.

I really want the batch file to stand alone without requiring (for example) a separate file containing a null character which can be copied when needed.

like image 777
Matthew Murdoch Avatar asked Apr 28 '10 15:04

Matthew Murdoch


1 Answers

create null file of size <size>:

fsutil file createnew <file> <size>
like image 85
Zimba Avatar answered Oct 27 '22 00:10

Zimba