在Windows 8.1上的管理员模式PowerShell中运行以下命令会产生奇怪的输出:
PS C:\> cat C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
以上是hosts文件的初始内容。
PS C:\> echo "127.0.0.1 example.com" >> C:\Windows\System32\drivers\etc\hosts
我用echo命令加了一行...
PS C:\> cat C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
1 2 7 . 0 . 0 . 1 e x a m p l e . c o m
PS C:\>
注意最后一行;它在每个被回显的字符之间都有空格。
知道为什么会这样吗?
3条答案
按热度按时间drnojrws1#
看起来最明显的解决方案是不使用
echo "text" >> file
。尝试使用add-content代替:这将为您提供所需的输出。
vbkedwbf2#
我认为问题是PowerShell默认使用Unicode。
这将实现您正在尝试做的事情:
46scxncf3#
在CMD中,而不是PS中:
回显IP地址主机名域名〉〉%系统驱动器%\Windows\System32\驱动程序\etc\主机
即:
返回127.0.0.1microsoft.com〉%系统驱动器%\Windows\System32\驱动程序\等\主机