예제 #1
0
 public void RunScript(string script)
 {
     if ((this.showCommandProxy != null) && !string.IsNullOrEmpty(script))
     {
         if (this.passThrough)
         {
             base.WriteObject(script);
         }
         else if (this.errorPopup != 0)
         {
             this.RunScriptSilentlyAndWithErrorHookup(script);
         }
         else if (this.showCommandProxy.HasHostWindow)
         {
             if (!this.showCommandProxy.SetPendingISECommand(script))
             {
                 this.RunScriptSilentlyAndWithErrorHookup(script);
             }
         }
         else if (!ConsoleInputWithNativeMethods.AddToConsoleInputBuffer(script, true))
         {
             base.WriteDebug(FormatAndOut_out_gridview.CannotWriteToConsoleInputBuffer);
             this.RunScriptSilentlyAndWithErrorHookup(script);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Executes a PowerShell script, writing the output objects to the pipeline.
        /// </summary>
        /// <param name="script">Script to execute</param>
        public void RunScript(string script)
        {
            if (_showCommandProxy == null || string.IsNullOrEmpty(script))
            {
                return;
            }

            if (_passThrough)
            {
                this.WriteObject(script);
                return;
            }

            if (ErrorPopup)
            {
                this.RunScriptSilentlyAndWithErrorHookup(script);
                return;
            }

            if (_showCommandProxy.HasHostWindow)
            {
                if (!_showCommandProxy.SetPendingISECommand(script))
                {
                    this.RunScriptSilentlyAndWithErrorHookup(script);
                }

                return;
            }

            if (!ConsoleInputWithNativeMethods.AddToConsoleInputBuffer(script, true))
            {
                this.WriteDebug(FormatAndOut_out_gridview.CannotWriteToConsoleInputBuffer);
                this.RunScriptSilentlyAndWithErrorHookup(script);
            }
        }
예제 #3
0
        /// <summary>
        /// Executes a PowerShell script, writing the output objects to the pipeline.
        /// </summary>
        /// <param name="script">Script to execute.</param>
        public void RunScript(string script)
        {
            if (_showCommandProxy == null || string.IsNullOrEmpty(script))
            {
                return;
            }

            if (_passThrough)
            {
                this.WriteObject(script);
                return;
            }

            if (ErrorPopup)
            {
                this.RunScriptSilentlyAndWithErrorHookup(script);
                return;
            }

            if (_showCommandProxy.HasHostWindow)
            {
                if (!_showCommandProxy.SetPendingISECommand(script))
                {
                    this.RunScriptSilentlyAndWithErrorHookup(script);
                }

                return;
            }

            // Don't send newline at end as PSReadLine shows it rather than executing
            if (!ConsoleInputWithNativeMethods.AddToConsoleInputBuffer(script, newLine: false))
            {
                this.WriteDebug(FormatAndOut_out_gridview.CannotWriteToConsoleInputBuffer);
                this.RunScriptSilentlyAndWithErrorHookup(script);
            }
        }