Note that there are some explanatory texts on larger screens.

plurals
  1. POC# or Python Pipe Blocked
    primarykey
    data
    text
    <p>I'm trying to simply be able to pipe the standard output of my program (written in C#) to another program (e.g. python script). My code simply writes to standard output using Console.Write(), and that works just fine when I'm not piping. The listen command just uses Console.Write() to write data from a separate Thread when it comes in from a socket that is setup.</p> <p><em>[Works - writes data to console as it is received]</em></p> <pre><code>myProgram.exe listen </code></pre> <p><em>[Does Not Work - nothing is written to console]</em></p> <pre><code>myProgram.exe listen | python filter.py </code></pre> <p>I'm not entirely sure what is going wrong, and haven't thought of a way to even troubleshoot this problem. My guess is that the problem has to do with the receiving Thread somehow blocking the standard output from piping data to another process, but I don't know how to test this. I'm looking for anyone who has an idea(s) on what the problem might actually be, or a way to further troubleshoot this. If you need code to help, I'd be willing to post snippets.</p> <p>How do I tell if the problem lies in C# or in Python?</p> <p><strong>EDIT:</strong> Note that the redirection operator (<strong>></strong>) does work though. So, <em>myProgram.exe listen > log.txt</em> does in fact write the data being written to standard out to the <em>log.txt</em> file. I've also tried following the example at <a href="http://linux.byexamples.com/archives/343/python-handle-string-from-pipelines-and-list-of-param/" rel="nofollow">http://linux.byexamples.com/archives/343/python-handle-string-from-pipelines-and-list-of-param/</a>.</p> <p><em><strong>[filter.py]</em></strong></p> <pre><code>import sys for line in sys.stdin: sys.stdout.write(line) </code></pre> <p><strong>EDIT:</strong> Console feedback</p> <p>I figured this is worth mentioning. The python script is getting called, but after waiting for 30 seconds (it should start outputting to standard out right away) I press <em>Ctrl + C</em> to stop the process and get the following.</p> <pre> >> myProgram.exe listen | python filter.py Traceback (most recent call last): File "filter.py", line 2, in for line in sys.stdin: KeyboardInterrupt ^C </pre> <p><strong>EDIT: @Aaronaught</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace echo { class Program { static void Main(string[] args) { if (args.Length &gt; 0) { foreach (string arg in args) { Console.Out.WriteLine(arg); } } else { Thread thread = new Thread(new ThreadStart(Receive)); thread.Start(); thread.Join(); } } static void Receive() { for (int i = 0; i &lt; 10; i++) { Console.Out.WriteLine(i); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload