Why does PowerShell ISE support this program in C #?

If I compile this C # code into an EXE file and run it in the Windows command shell, it works fine: output a line, waiting on the same line for some user input, and then input, repeat this input. Running in PowerShell v3 also works great. If, however, I run the same EXE file in PowerShell ISE V3, it never displays output from Write, and it hangs on ReadLine. (Aside, he will issue a conclusion from Writeif he later follows 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 error or is there some kind of property to configure it to work ??

+5
source share
3 answers

ISE console.

  • [Console], [console]:: BackgroundColor = "".
    • API- (write-host, [Console], , ISE, Remoting .

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

+4

, powershell ise .\ConsoleApplication1.exe call start .\ConsoleApplication1.exe , stdin.

+4

The Powershell read-host will be read from the console. You can do a read-host from C #. The execution of PS commands from C # is documented in MSDN in the Powershell sections. The following shows how method calls using a Powershell script - should be easily converted to C #. Note that $ host must be passed to a C # program. Therefore, you will need to load the C # program as an assembly in ISE and call Main () as: [myclass] :: Main ($ host) (against calling EXE as a separate program)

[powershell]::create().AddScript('param($ho) $ho.ui.readline()').AddArgument($host).Invoke()
0
source

All Articles