Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PowerShell ISE hang on this C# program?

If I compile this c# code to an EXE file and run in a Windows command shell it runs fine: outputting the prompt, waiting on the same line for some user input followed by enter, echoing that input. Running in a PowerShell v3 shell it also runs fine. If, however, I run this same EXE file in PowerShell ISE V3, it never emits output from Write and it hangs on the ReadLine. (As an aside, it will emit output from Write if it is later followed by a WriteLine.)

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.Write("invisible prompt: ");
            var s = System.Console.ReadLine();
            System.Console.WriteLine("echo " + s);
        }
    }
}

Is this an ISE bug or is there some property to adjust to make it work...?

like image 577
Michael Sorens Avatar asked Apr 19 '13 21:04

Michael Sorens


People also ask

Why is PowerShell running on my computer?

The reason PowerShell open on Startup is likely because you mistakenly added Windows PowerShell shortcut to the Start-up folder. What is this? If you also look at the Start-up tab of Task Manager, Windows PowerShell will be listed and status displayed as Enabled.

How do I stop a running PowerShell code?

Open a PowerShell console session, type exit , and press the Enter key. The PowerShell console will immediately close. This keyword can also exit a script rather than the console session.

How do you control C in PowerShell?

CTRL + C can be used when the context is unambiguous (when there is no text selected). CTRL + TAB Note: Tab to next script works only when you have a single Windows PowerShell tab open, or when you have more than one Windows PowerShell tab open, but the focus is in the Script Pane.

Does PowerShell ISE actually run the commands?

The Windows PowerShell Integrated Scripting Environment (ISE) is a host application for Windows PowerShell. In the ISE, you can run commands and write, test, and debug scripts in a single Windows-based graphic user interface.


1 Answers

The ISE has no support for the console class.

  • No support for the [Console] class, try [console]::BackgroundColor = 'white'.
    • In general, scripts should use the host API's (write-host, instead of the [Console] class, so that they work in both the console, ISE, Remoting and other shells.

Reference: http://blogs.msdn.com/b/powershell/archive/2009/04/17/differences-between-the-ise-and-powershell-console.aspx

like image 135
Andy Arismendi Avatar answered Oct 02 '22 10:10

Andy Arismendi