Jul-03-2018, 12:42 AM
file runpipeline.py:
def run_pipe_line(*a): from subprocess import PIPE, Popen if len(a) == 1 and isinstance(a[0],(list,tuple)): # a list of commands instead of one per arg a = a[0] l = len(a) if l < 1: # if no commands then no results return [] if l < 2: # if just one command then just do it p = [Popen(a[0])] else: for n in range(l): if n < 1: # if this is first command p = [Popen(a[0],stdout=PIPE)] elif n == l-1: # if this is last command p.append(Popen(a[l-1],stdin=p[n-1].stdout)) else: p.append(Popen(a[n],stdin=p[n-1].stdout,stdout=PIPE)) r = [] for n in range(l): # wait for all and collect results r.append(p[n].wait()) return ra command is a list of strings (arguments, tokens). a pipeline is either a list of commands or a command per function call argument. so you might have commands in cmd1, cmd2, and cmd3 ... you can do either
run_pipe_line([cmd1,cmd2,cmd3])
or just run_pipe_line(cmd1,cmd2,cmd3)
.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.