回声“串” > Windows PowerShell中的文件将不可打印字符附加到文件 [英] echo "string" > file in Windows PowerShell appends non-printable character to the file
问题描述
在Windows PowerShell中:
echo "string" > file.txt
在Cygwin中:
$ cat file.txt
:::s t r i n g
$ dos2unix file.txt
dos2unix: Skipping binary file file.txt
我想要一个简单的字符串。我该怎么做?也就是说,当我说 cat file.txt
时,我只需要string作为输出。
I want a simple "string" in the file. How do I do it? I.e., when I say cat file.txt
I need only "string" as output. I am echoing from Windows PowerShell and that cannot be changed.
推荐答案
尝试 echostring|我的回答从Windows PowerShell回声,不能更改。 out-file -encoding ASCII file.txt
以获取一个简单的ASCII编码的txt文件。
Try echo "string" | out-file -encoding ASCII file.txt
to get a simple ASCII-encoded txt file.
echo "string" | out-file -encoding ASCII file.txt
将生成一个包含以下内容的文件:
will produce a file with the following contents:
73 74 72 69 6E 67 0D 0A (string..)
但
echo "string" > file.txt
将生成一个包含以下内容的文件:
will produce a file with the following contents:
FF FE 73 00 74 00 72 00 69 00 6E 00 67 00 0D 00 0A 00 (ÿþs.t.r.i.n.g.....)
(字节顺序标记FF FE表示文件是UTF-16(LE) :0xFF 0xFE后跟2个字节对xx 00 xx 00 xx 00正常0-127 ASCII字符
(Byte order mark FF FE indicates the file is UTF-16 (LE). The signature for UTF-16 (LE) = 2 bytes: 0xFF 0xFE followed by 2 byte pairs. xx 00 xx 00 xx 00 for normal 0-127 ASCII chars
这篇关于回声“串” > Windows PowerShell中的文件将不可打印字符附加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!