操作系统: Windows 7 SP1
我使用以下命令在cmd.exe中创建了一个空文本文件:
echo 2> .gitignore该命令将std::cerr (本例中为空输出)重定向到.gitignore文件。结果文件有ANSI编码,但我需要UTF-8。我能否指出>操作所需的编码(>)?
发布于 2015-08-02 12:42:02
通过批处理文件输出重定向是不可能的。
使用内置实用程序的唯一方法是调用powershell:
powershell -c "[io.file]::WriteAllText('.gitignore','',[System.Text.Encoding]::UTF8)"发布于 2018-01-11 13:06:35
基于从批处理生成几乎任何字符,包括TAB。的dbenham纯批解决方案
@echo off
(set LF=^
%=empty=%
)
::Create variables to store BOM bytes
call :hexprint "0xEF" EF
call :hexprint "0xBB" BB
call :hexprint "0xBF" BF
<nul SET /P "=%EF%%BB%%BF%"> output.txt
exit /b
:hexPrint string [rtnVar]
for /f eol^=^%LF%%LF%^ delims^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b发布于 2017-12-07 11:35:44
创建一个..bat/..cmd文件,类似于:
<nul SET /P "=123"> output.txt然后在你喜欢的HEX编辑器中用EF BB BF字节替换123。
要编辑这个..bat/..cmd文件,以后不应该使用窗口的Notepad.exe,因为它在"Save“模式下将BOM -字节转换为问号(或者,在"Save 8”模式下,它将不必要的BOM添加到脚本文件本身)。相反,我们可以使用"UTF-8 (witout )“模式使用Notepad++。
https://stackoverflow.com/questions/31771793
复制相似问题