相关疑难解决方法(0)

使用PowerShell以UTF-8编写文件而不使用BOM

Out-File 似乎在使用UTF-8时强制BOM:

$MyFile = Get-Content $MyPath
$MyFile | Out-File -Encoding "UTF8" $MyPath
Run Code Online (Sandbox Code Playgroud)

如何使用PowerShell以UTF-8编写没有BOM的文件?

powershell encoding byte-order-mark utf-8

225
推荐指数
9
解决办法
21万
查看次数

将PowerShell的默认输出编码更改为UTF-8

默认情况下,当您将命令的输出重定向到文件或将其传递到PowerShell中的其他内容时,编码为UTF-16,这是无用的.我想把它改成UTF-8.

它可以通过替换>foo.txt语法来逐个进行,| out-file foo.txt -encoding utf8但是每次都必须重复这是很尴尬的.

在PowerShell中设置内容的持久方法是将它们放入\Users\me\Documents\WindowsPowerShell\profile.ps1; 我已经验证这个文件确实是在启动时执行的.

有人说输出编码可以设置,$PSDefaultParameterValues = @{'Out-File:Encoding' = 'utf8'}但我已经尝试过,它没有任何效果.

https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/谈到$OutputEncoding乍一看似乎应该是相关的,但后来谈到输出被编码在ASCII中,这不是实际发生的事情.

如何设置PowerShell使用UTF-8?

powershell utf-8 character-encoding

70
推荐指数
1
解决办法
8万
查看次数

.gitignore被Visual Studio忽略了吗?

我有一个git项目,我使用Visual Studio 2013和Git.

我注意到我的.gitignore文件中列出的许多文件(如果不是全部)仍然在团队资源管理器窗口中列为待定更改.

但是,在git status使用bash时,我看不到文件(正如预期的那样).为什么会发生这种情况,更重要的是,我如何让Visual Studio将我的.gitignore文件视为与git bash相同?

.gitignore 文件:

GitIgnore文件

待更改窗口(团队资源管理器):

待更改窗口

git visual-studio visual-studio-2012 visual-studio-2013

7
推荐指数
1
解决办法
2269
查看次数

PowerShell:设置内容替换单词并编码无 BOM 的 UTF8

我想将 csv 文件中的 \ 转义为 \\ 以上传到 Redshift。以下简单的 PowerShell 脚本可以按预期将 $TargetWord \ 替换为 $ReplaceWord \\ ,但使用 bom 导出 utf-8 有时会导致 Redshift 复制错误。

任何改进它的建议将不胜感激。先感谢您。

Exp_Escape.ps1

Param(
    [string]$StrExpFile,
    [string]$TargetWord,
    [string]$ReplaceWord
)

# $(Get-Content "$StrExpFile").replace($TargetWord,$ReplaceWord) | Set-Content -Encoding UTF8 "$StrExpFile"
Run Code Online (Sandbox Code Playgroud)

powershell utf-8

3
推荐指数
1
解决办法
4162
查看次数