ant-druha / intellij-powershell

Adds PowerShell language support to IntelliJ-based IDEs.
https://plugins.jetbrains.com/plugin/10249-powershell
Apache License 2.0
73 stars 20 forks source link

Integrated PowerShell Console behaves differently to pwsh with Write-Error #14

Open glawrence opened 5 years ago

glawrence commented 5 years ago

I have created a simple PowerShell script (with .ps1 extension, which GitHub did not like, hence it is .txt) as attached:

OutputDemo.txt

I am running PowerShell Core 6.1.2 on my Mac. If I type pwsh in the Terminal I can then type ./OutputDemo.ps1 and I see the following:

Hello World - Part 1
/Users/xxxxxxxxxx/IdeaProjects/PowerShell/OutputDemo.ps1 : Oh no!
At line:1 char:1
+ ./OutputDemo.ps1
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,OutputDemo.ps1

Finished

If I open the file with IntelliJ IDEA 2018.3.3 and the "PowerShell v2.0.1" plugin and run the script from there, I see the following:

Hello World - Part 1
Finished
/Users/xxxxxxxxxx/IdeaProjects/PowerShell/OutputDemo.ps1 : Oh no!
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,OutputDemo.ps1

My key issue is that the error output is not being displayed in the same way as the interactive PowerShell console, the lines are all out of order and it is very confusing. Interestingly the error output is also different as the line, char information is not displayed.

ForNeVeR commented 1 year ago

The difference happens because we run the script via powershell -File <script file name>, while you likely run your script as a PowerShell command (i.e. just ./file.ps1).

I'll reclassify this as a feature request: let's add a way to run a command instead of a script in a run configuration. This way, it'll be possible to run a script as powershell -c ./myscript.ps1 instead of powershell -file ./myscript.ps1, and you'll get all the ordinary features of the command execution mode.