intellij-powershell icon indicating copy to clipboard operation
intellij-powershell copied to clipboard

Integrated PowerShell Console behaves differently to pwsh with Write-Error

Open glawrence opened this issue 5 years ago • 1 comments

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.

glawrence avatar Jan 18 '19 09:01 glawrence

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.

ForNeVeR avatar Sep 13 '23 21:09 ForNeVeR