以下是我在项目目录中运行某个 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/