powershell - 如何让 Powershell ISE 支持颜色和非 ASCII 字符?

标签 powershell powershell-ise

以下是我在项目目录中运行某个 grunt 任务时 Windows PowerShell 的一些示例输出:

Done, without errors.


Execution Time (2015-08-25 01:57:14 UTC)
loading tasks                9ms  ██████ 17%
loading grunt-contrib-copy  23ms  ███████████████ 43%
copy:styles                 20ms  █████████████ 38%
Total 53ms

Running "autoprefixer:server" (autoprefixer) task
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autoprefixe
r]).process() instead
File .tmp/styles/main.css created.

“完成,没有错误”为绿色,“.tmp/styles/main.css”为青色。

在 Powershell ISE 中运行相同的命令,会产生以下结果:
[32mDone, without errors.[39m


Execution Time (2015-08-25 01:58:40 UTC)
loading tasks                9ms  ███████ 20%
loading grunt-contrib-copy  20ms  ████████████████ 45%
copy:styles                 14ms  ███████████ 32%
Total 44ms

[4mRunning "autoprefixer:server" (autoprefixer) task[24m
grunt : Autoprefixer's process() method is deprecated and will removed in next major release. Use 
postcss([autoprefixer]).process() instead
At line:1 char:1
+ grunt serve
+ ~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Autoprefixer's ...ocess() instead:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

File .tmp/styles/main.css created.

颜色不能正确解释,非 ASCII 字符也不能正确解释。

我尝试寻找解决方案,但没有成功。如何让 PowerShell ISE 表现得更像 PowerShell?看起来 PS ISE 只是普通 PS 的包装,但肯定还有更多。

更新:遇到this post上面写着“控制台应用程序输出不是彩色的”。这是否意味着无法通过 PowerShell ISE 获得类似 PowerShell 的输出?

最佳答案

我会质疑为什么您希望它首先在 PowerShell ISE 中工作。是否只是为了在开发/调试它时您可以看到正确的输出,而正常执行在 powershell.exe 中完成? ?

如果是这样,您可以通过将其放在脚本顶部来解决它:

if ($Host.Name -like '*ISE*') {
    Start-Process -FilePath powershell.exe -ArgumentList '-NoExit','-ExecutionPolicy',(Get-ExecutionPolicy),'-File',$PSCommandPath
    return
}

本质上,每当您从 ISE 中运行脚本时,它都会改为在新的 powershell 控制台主机中运行脚本。

关于powershell - 如何让 Powershell ISE 支持颜色和非 ASCII 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194495/

相关文章:

powershell - 如何从文件夹中的所有文本文件中删除单词?

powershell 远程安装 msi 失败

PowerShell:从字符串中提取时间戳

Powershell 工具模块项目构建无法正常工作

powershell-3.0 - 计算 PowerShell 中空行之前的行 #

Powershell 2 ISE,不在导入模块中的断点处停止

用于查询和删除早于 "x"天的打印作业的 PowerShell 脚本

powershell - PowerShell Pscx Expand-Archive方法故障检测

iis - 如何运行 PowerShell 脚本 "in"IIS?

security - 使用PowerShell V4通过gmail发送邮件