in reply to Re: Connecting Perl's STDIN and STDOUT to .Net StreamReader
in thread Connecting Perl's STDIN and STDOUT to .Net StreamReader

The .Net Peek() method actually belongs to the StreamReader class of Which Sys.Diag.Process.Stdout is an instance of. It always returns the next char in a Stream or -1 if the Stream is closed or doesn't support Peek. I would hope otherwise it would block if the Stream is open and just empty. I will re-examine this part of the documentation.

I am suspicious of Perl's buffering. However, when I try running a similar Perl process using Win32 command with type(cat) it works fine.

  • Comment on Re^2: Connecting Perl's STDIN and STDOUT to .Net StreamReader

Replies are listed 'Best First'.
Re^3: Connecting Perl's STDIN and STDOUT to .Net StreamReader
by BrowserUk (Patriarch) on Sep 03, 2008 at 12:12 UTC

    I think Corion called it right. From the docs (my emphasis):

    The current position of the StreamReader object is not changed by Peek. The returned value is -1 if no more characters are currently available

    That suggests .Peek will return -1 when there is nothing currently available. Not when nothing more will ever become available (in a microsecond from now).

    Your fix is probabaly to use the "standard c# idiom":

    using (StreamReader sr = ... ) { string line; // Read and display lines from the file until the end +of // the file is reached. while ((line = sr.ReadLine()) != null) { ... } } }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.