-
-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt error in remote PSSession #708
Comments
Can you repro that and then execute |
PSMessageDetails :
TargetObject : |
I'm getting the same on the following;
|
This is the offending code:
We are trying to revert the OutputEncoding to its original value. I wonder if we need to be checking the value of |
Here's what my
I am remoting onto the server via |
I have exactly the same OutputEncoding as labrunning. And indeed you've found the piece of code generating the error :) [Console]::OutputEncoding = [Text.Encoding]::UTF8
Exception setting "OutputEncoding": "The handle is invalid.
"
At line:1 char:1
+ [Console]::OutputEncoding = [Text.Encoding]::UTF8
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting |
Can one of you try changing Utils.ps1 line 42 from this:
to
I'm not crazy about just swallowing the exception but if it can get past this and still work correctly ... |
Unfortunately, I get the same error. |
How about this:
|
Still the same error :( |
Huh. And the error you get indicates it is coming from the line (42) that you modified in Utils.ps1? Is it possible the error is originating from 36? Maybe comment out line 36 and see if it still fails. |
Commenting out line 36 with the last suggested change to line 42 now works for me. |
Yep! works for me too :) |
Would be better to detect when we would get the IOException but not sure how to do that. Fix #708
Since I'm not able to repro this, can one of you see if my PR branch above fixes the issue for you? I'd like to verify that before merging it. |
I had this problem in PowerShell ISE too. $Global:OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() Worked fine from a Windows PowerShell terminal, also PowerShell 7.2.1 from Microsoft Store. But in PowerShell ISE it gave: Exception setting "OutputEncoding": "The handle is invalid. Some more error details# Exception:
## Exception\ErrorRecord:
Exception setting "OutputEncoding": "The handle is invalid.
"
## Exception\WasThrownFromThrowStatement:
False
## Exception\Message:
Exception setting "OutputEncoding": "The handle is invalid.
"
## Exception\InnerException:
System.IO.IOException: The handle is invalid.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Console.set_OutputEncoding(Encoding value)
at CallSite.Target(Closure , CallSite , Type , Object )
## Exception\TargetSite:
Void CheckActionPreference(System.Management.Automation.Language.FunctionContext, System.Exception)
## Exception\StackTrace:
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
## Exception\Source:
System.Management.Automation
## Exception\HResult:
-2146233087
# CategoryInfo:
## CategoryInfo\Category:
NotSpecified
## CategoryInfo\Reason:
SetValueInvocationException
# FullyQualifiedErrorId:
## FullyQualifiedErrorId\Length:
20
## FullyQualifiedErrorId\Chars:
char Chars(int index) {get;}
# InvocationInfo:
## InvocationInfo\ScriptLineNumber:
2
## InvocationInfo\OffsetInLine:
5
## InvocationInfo\HistoryId:
-1
## InvocationInfo\Line:
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
## InvocationInfo\PositionMessage:
At line:2 char:5
+ [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## InvocationInfo\PipelineLength:
0
## InvocationInfo\PipelinePosition:
0
## InvocationInfo\ExpectingInput:
False
## InvocationInfo\CommandOrigin:
Internal
# ScriptStackTrace:
## ScriptStackTrace\Length:
35
## ScriptStackTrace\Chars:
char Chars(int index) {get;}
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException Then I figured out by goofing around that, if you've had any output from CMD first, like so for instance (see under), then it worked. $null = cmd /c '' So in my jank script for using winget-cli to update certain apps if an update is available, due to the output of winget-cli being utf8, I now use following before using winget-cli: $null = cmd /c ''
$Global:OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() I thought this find might help others, so figured I should write this somewhere. |
System Details
Issue Description
When I am in a remote PSSession, the prompt displays an error message:
C:\Repo [Error: Exception setting "OutputEncoding": "The handle is invalid.
"][ComputerName]: >
When I am in a local PowerShell session on the same computer, the prompt works fine.
C:\Repo [master ≡]>
The text was updated successfully, but these errors were encountered: