如何使Powershell ISE支持颜色和非ASCII字符?
以下是我在项目目录中运行特定grunt任务时Windows PowerShell的一些示例输出:如何使Powershell ISE支持颜色和非ASCII字符?,powershell,powershell-ise,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 ███
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的包装器,但肯定还有更多
更新:发现“控制台应用程序输出不丰富多彩”。这是否意味着无法通过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控制台主机中运行脚本。出于好奇,您是否使用git bash之类的工具?这些颜色字符在我看来像Bash颜色字符,ISE使用cmd.exe作为其主机(我相信)。如果脚本中有任何读取主机
调用,这将导致问题。请尝试并查看。在ISE中运行时,对Read Host
的调用通常会创建一个提示窗口,您可以在其中键入(因为您无法在ISE的输出窗口中键入),但如果您从脚本中启动的单独PowerShell进程中调用它,则不会显示该窗口。看看我的答案。@jpmc26我已经试过了;它似乎工作得很好<代码>读取主机
在控制台主机中工作;它不会弹出一个新窗口,而是让你直接输入。阅读您的答案后,看起来您正在ISE中运行powershell.exe
(这意味着它正在共享ISE的“控制台”窗口)。在我的方法中,我特别使用启动进程
,因为它在自己的控制台主机中打开一个全新的powershell.exe
实例。