From 1ec5676f25d9c6e65b7fae481bd518cb7ed660ef Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 11 Feb 2016 15:33:32 -0800 Subject: [PATCH] Fix "handle is invalid" error on AppVeyor --- src/Microsoft.PowerShell.Linux.Host/host.cs | 3 ++- src/Microsoft.PowerShell.Linux.Host/main.cs | 7 +++++++ src/Microsoft.PowerShell.Linux.Host/ui.cs | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Linux.Host/host.cs b/src/Microsoft.PowerShell.Linux.Host/host.cs index d04177d4a..f4fa3e253 100644 --- a/src/Microsoft.PowerShell.Linux.Host/host.cs +++ b/src/Microsoft.PowerShell.Linux.Host/host.cs @@ -16,6 +16,7 @@ namespace Microsoft.PowerShell.Linux.Host public MyHost(Listener Listener) { this.Listener = Listener; + this.myHostUserInterface = new MyHostUserInterface(Listener.HasUI); } /// @@ -44,7 +45,7 @@ namespace Microsoft.PowerShell.Linux.Host /// A reference to the implementation of the PSHostUserInterface /// class for this application. /// - private MyHostUserInterface myHostUserInterface = new MyHostUserInterface(); + private MyHostUserInterface myHostUserInterface; /// /// A reference to the runspace used to start an interactive session. diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs index dc263e217..aec3e215c 100644 --- a/src/Microsoft.PowerShell.Linux.Host/main.cs +++ b/src/Microsoft.PowerShell.Linux.Host/main.cs @@ -187,8 +187,15 @@ OPTIONS set { this.exitCode = value; } } + /// + /// Gets or sets a value indicating whether UI should exit. + /// + public bool HasUI; + public Listener(string initialScript, bool loadProfiles) { + HasUI = (initialScript == null) ? true : false; + // Create the host and runspace instances for this interpreter. // Note that this application does not support console files so // only the default snap-ins will be available. diff --git a/src/Microsoft.PowerShell.Linux.Host/ui.cs b/src/Microsoft.PowerShell.Linux.Host/ui.cs index ed6817e1b..c1c6626ea 100644 --- a/src/Microsoft.PowerShell.Linux.Host/ui.cs +++ b/src/Microsoft.PowerShell.Linux.Host/ui.cs @@ -17,10 +17,18 @@ namespace Microsoft.PowerShell.Linux.Host /// internal class MyHostUserInterface : PSHostUserInterface, IHostUISupportsMultipleChoiceSelection { + /// + /// Public constructor + /// + public MyHostUserInterface(bool hasUI) + { + myRawUi = (hasUI) ? new MyRawUserInterface() : null; + } + /// /// A reference to the PSRawUserInterface implementation. /// - private MyRawUserInterface myRawUi = new MyRawUserInterface(); + private MyRawUserInterface myRawUi; /// /// Gets an instance of the PSRawUserInterface class for this host