4

Here is some sample output from Windows PowerShell when I run a certain grunt task in my project directory:

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.

"Done, without errors" is in green and ".tmp/styles/main.css" is in cyan.

Running the same command in Powershell ISE, produces the following:

[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.

Colors are not interpreted correctly, and neither are non-ASCII characters.

I have tried searching for a solution, but with no success. How can I make PowerShell ISE behave more like PowerShell? It would seem like PS ISE is just a wrapper around regular PS, but there must be more to that.

Update: came across this post which says that "Console Application output is not colorful". Would this mean there is no way to get PowerShell-like output through PowerShell ISE?

briantist
  • 45,546
  • 6
  • 82
  • 127
geoff
  • 2,251
  • 1
  • 19
  • 34

2 Answers2

0

I would question why you want this to work in PowerShell ISE to begin with. Is it just so that you can see the correct output while developing/debugging it, while the normal execution gets done in powershell.exe?

If so, you could workaround it by putting this at the top of your script:

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

Essentially, whenever you run the script from within ISE, it will run the script in a new powershell console host instead.

briantist
  • 45,546
  • 6
  • 82
  • 127
  • This would cause problems if there are any `Read-Host` calls in the script. – jpmc26 Aug 25 '15 at 03:14
  • Try it and see. When running in ISE, calls to `Read-Host` normally create a prompt window where you can type in (since you can't type in on ISE's output window), but it doesn't show up if you call it from a separate PowerShell process you started in the script. See my answer [here](http://stackoverflow.com/a/12807629/1394393). – jpmc26 Aug 25 '15 at 03:30
  • @jpmc26 I have tried it; it seems to work perfectly fine. `Read-Host` works in the console host; it just doesn't pop up a new window, it lets you type directly. After reading your answer, it looks like you are running `powershell.exe` within ISE (which means it's sharing ISE's "console" window). In my method, I use `Start-Process` specifically because it opens a brand new `powershell.exe` instance, in its own console host. – briantist Aug 25 '15 at 03:34
0

Out of curiosity, are you using something like git-bash? Those color characters seem like Bash color characters to me, and ISE uses cmd.exe as its host (I believe).

Carlos Nunez
  • 2,047
  • 1
  • 18
  • 20