1

I'm trying to process log file output and put it on the plot. However, I can't put my hands around Get-Content -Wait. It seems that my C# program is not being invoked at all. Works fine without the wait switch, but that's not what I need. Simple sample:

using static System.Console;

public class Program
{
    public static void Main(string[] args)
    {
        WriteLine("Starting...");
        if (IsInputRedirected)
        {
            while (In.Peek() != -1)
            {
                Write("[");
                var input = In.ReadLine();
                WriteLine($"{input}]");
            }
            WriteLine("... done.");
        }
        else
        {
            WriteLine("Nothing");
        }
    }
}

With the sample calls like:

gc .\Program.cs | .\bin\Debug.ConsoleTest.exe

and

gc .\Program.cs -Wait | .\bin\Debug.ConsoleTest.exe

Does anybody know how to receive the output of Get-Content with -Wait from console application?

Mike
  • 18,257
  • 1
  • 18
  • 12
  • What is "Get-Content" or "-Wait" ? it looks like you're just receiving data from another command to echo. – BugFinder Feb 15 '17 at 13:13
  • 1
    [This](http://stackoverflow.com/questions/19919180/get-content-wait-not-working-as-described-in-the-documentation) post says it's a bug, and that it has been fixed in Powershell 5. – Palle Due Feb 15 '17 at 13:27

1 Answers1

0

Get-content is used to get the content of a file not strip the output of the program u start. you can use the get-content on the logfile u genarate but know that if u use wait it will be waiting until u kill the procces waiting.

so in a nutshell Get-content -Wait is only used to follow the a log file being written from a other process.

just use .\Program.cs | .\bin\Debug.ConsoleTest.exe and it will wait until exited. if you want the stdout and the stderror you need a construction like described Here (please note there is a problem using $stdout = $p.StandardOutput.ReadToEnd() ;$stderr = $p.StandardError.ReadToEnd() for big outputs, they deadlock each other)

Community
  • 1
  • 1
Bert Levrau
  • 975
  • 8
  • 11