How can I use input redirection <() with python's subprocess.Popen?
For example, say I have:
import subprocess
class Test():
def __init__(self):
self.proc = subprocess.Popen(["sort file1.txt file2.txt)"],
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
def __iter__(self):
return self
def __next__(self):
while True:
line = self.proc.stdout.readline()
if not line:
raise StopIteration
return line.strip().decode('utf-8')
t = Test()
for line in t:
print(line)
The above works perfectly fine, but really I need the command to do something like:
sort <(python file1.txt) <(python file2.txt)
That doesnt seem to run anything though, even this doesnt work
sort <(cat file1.txt) <(cat file2.txt)
How can I get this to work with python's subprocess, and iterate through the results line by line