Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upNamedPipeConnectionInfo <= Enter-PSHostProcess #881
Conversation
|
@SeeminglyScience let me know if you see anything wrong with this in the scope of the threading model... I think it will be fine since it's a totally separate runspace... |
| else | ||
| { | ||
| var psCommand = new PSCommand().AddCommand("Get-Runspace"); | ||
| StringBuilder sb = new StringBuilder(); |
TylerLeonhardt
Mar 18, 2019
Author
Member
got me!
got me!
| { | ||
| foreach (var p in runspaces) | ||
| // Create a remote runspace that we will invoke Get-Runspace in | ||
| using(var rs = RunspaceFactory.CreateRunspace(new NamedPipeConnectionInfo(pid))) |
rkeithhill
Mar 18, 2019
Collaborator
Will this work with all supported versions of PowerShell?
Will this work with all supported versions of PowerShell?
TylerLeonhardt
Mar 18, 2019
•
Author
Member
Good catch... this use to be a runtime check using Enter-PSHostProcess but now it's an assembly load check...
This will work in PowerShell 5.1+ so it's not a problem in this PR.
But when I backport I need to ifdef this properly...
Good catch... this use to be a runtime check using Enter-PSHostProcess but now it's an assembly load check...
This will work in PowerShell 5.1+ so it's not a problem in this PR.
But when I backport I need to ifdef this properly...
|
LGTM :) Just some optional nits |
| rs.Open(); | ||
| ps.Runspace = rs; | ||
| // returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later. | ||
| runspaces = ps.AddCommand("Get-Runspace").Invoke<PSObject>(); |
SeeminglyScience
Mar 19, 2019
Collaborator
Suggested change
runspaces = ps.AddCommand("Get-Runspace").Invoke<PSObject>();
runspaces = ps.AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace").Invoke<PSObject>();
| runspaces = ps.AddCommand("Get-Runspace").Invoke<PSObject>(); | |
| runspaces = ps.AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace").Invoke<PSObject>(); |
| } | ||
| } | ||
| else | ||
| { | ||
| var psCommand = new PSCommand().AddCommand("Get-Runspace"); |
SeeminglyScience
Mar 19, 2019
Collaborator
Suggested change
var psCommand = new PSCommand().AddCommand("Get-Runspace");
var psCommand = new PSCommand().AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace");
| var psCommand = new PSCommand().AddCommand("Get-Runspace"); | |
| var psCommand = new PSCommand().AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace"); |
| { | ||
| foreach (var p in runspaces) | ||
| // Create a remote runspace that we will invoke Get-Runspace in |
SeeminglyScience
Mar 19, 2019
Collaborator
Suggested change
// Create a remote runspace that we will invoke Get-Runspace in
// Create a remote runspace that we will invoke Get-Runspace in.
| // Create a remote runspace that we will invoke Get-Runspace in | |
| // Create a remote runspace that we will invoke Get-Runspace in. |
| }); | ||
| rs.Open(); | ||
| ps.Runspace = rs; | ||
| // returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later. |
SeeminglyScience
Mar 19, 2019
Collaborator
Suggested change
// returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
// Returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
| // returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later. | |
| // Returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later. |
| IEnumerable<Runspace> runspaces = await editorSession.PowerShellContext.ExecuteCommandAsync<Runspace>(psCommand, sb); | ||
| if (runspaces != null) | ||
| // If the processId is a valid int, we need to run Get-Runspace within that process | ||
| // otherwise just use the current runspace |
SeeminglyScience
Mar 19, 2019
Collaborator
Suggested change
// otherwise just use the current runspace
// otherwise just use the current runspace.
| // otherwise just use the current runspace | |
| // otherwise just use the current runspace. |
| await editorSession.PowerShellContext.ExecuteCommandAsync(exitCommand); | ||
| if (runspaces != null) | ||
| { | ||
| foreach (dynamic p in runspaces) |
SeeminglyScience
Mar 19, 2019
•
Collaborator
Consider using a more descriptive variable name like runspace or even pso.
Edit: didn't realize this was existing code, but maybe still worth fixing.
Consider using a more descriptive variable name like runspace or even pso.
Edit: didn't realize this was existing code, but maybe still worth fixing.
cc @adamdriscoll
Before, we relied on Enter-PSHostProcess... I noticed that this wasn't working and instead the GeRunspace function would return results from the current runspace instead.
This switches to using
NamedPipeConnectionInfoAPI way of invoking something on a remote runspace.