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

前端 未结 4 776
一整个雨季
一整个雨季 2020-12-31 12:58

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:

         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-31 13:16

    An alternative to the accepted answer which doesn't involve having to put null characters into the batch file is as follows:

    @echo off
    
    set NULL_FILE=null.txt
    set DEBUG_COMMANDS=write-null.dbg
    
    echo e 100 >%DEBUG_COMMANDS%
    echo 0 >>%DEBUG_COMMANDS%
    echo n %NULL_FILE% >>%DEBUG_COMMANDS%
    echo rbx >>%DEBUG_COMMANDS%
    echo 0 >>%DEBUG_COMMANDS%
    echo rcx >>%DEBUG_COMMANDS%
    echo 1 >>%DEBUG_COMMANDS%
    echo w >>%DEBUG_COMMANDS%
    echo q >>%DEBUG_COMMANDS%
    
    debug < %DEBUG_COMMANDS% >nul
    
    del %DEBUG_COMMANDS%
    

    This is obviously more verbose and also has the downside that it won't work on Win64 machines (due to debug no longer being available in those environments).

提交回复
热议问题