Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for Why does shell=True work when piping commands together?

Current License: CC BY-SA 3.0

10 events
when toggle format what by license comment
Mar 13, 2013 at 20:47 comment added Alex Reynolds Thanks, but your first code snippet still does not work. I had already updated my question to fix the typo — what's there is what I want to do (eventually replacing for line in sys.stdin: with for line in some_file_handle:, which could be sys.stdin or a handle to a file read off of disk). I'll try out your new code snippets to see if those work.
Mar 13, 2013 at 20:00 history edited jfs CC BY-SA 3.0
foo - < data | bar - > result
Mar 13, 2013 at 19:25 comment added jfs @AlexReynolds: The code in my answer does work. It emulates foo - | bar -. Update your question to include the real example of what you want to do. I've updated the answer to show how to feed input line-by-line.
Mar 13, 2013 at 19:25 history edited jfs CC BY-SA 3.0
feed modified input line-by-line
Mar 13, 2013 at 18:13 comment added Alex Reynolds Unfortunately, this didn't work. I need to process data one line at a time, in any case, and also be able to handle file handles other than stdin. It doesn't look like for line in sys.stdin: ... bar_process.communicate(line) works.
Mar 13, 2013 at 0:50 comment added jfs @AlexReynolds: bar_process.stdin is None so indeed bar_process.communicate() is just bar_process.wait() in this case.
Mar 13, 2013 at 0:33 comment added jfs @AlexReynolds: the code emulates your 1st example (there is no need to first read from stdin, only to write it immediately to foo. foo process can read from stdin by itself).
Mar 13, 2013 at 0:28 comment added Mattie B communicate() would likely be standing in for wait(), since bar_process will never provide output to Python.
Mar 13, 2013 at 0:21 comment added Alex Reynolds Why would I use bar_process.communicate()? Wouldn't I write data to foo_process?
Mar 13, 2013 at 0:17 history answered jfs CC BY-SA 3.0

AltStyle によって変換されたページ (->オリジナル) /