Just a bit simpler:
If you relay on Python2, you don't have the nice argument unpacking.
You can 'clone' this functionallity:
def pipe(command1, command2): pout = subprocess.Popen(command1, stdout=subprocess.PIPE) pin = subprocess.Popen(command2, stdin=pout.stdout) pout.wait() pin.wait()If you want to pipe many processes:
def many_pipe(*commands): first, *rest = [shlex.split(cmd) for cmd in commands] procs = [subprocess.Popen(first, stdout=subprocess.PIPE)] for cmd in rest: proc = subprocess.Popen(cmd, stdin=procs[-1].stdout, stdout=subprocess.PIPE) procs.append(proc) [p.wait() for p in procs] return procs[-1].stdout.read().decode(sys.getdefaultencoding())I use shlex.split to split the command. If you depend on user input, you should not use shlex.split.
If you relay on Python2, you don't have the nice argument unpacking.
You can 'clone' this functionallity:
commands = ['ls -l', 'grep foo', 'sort'] first, rest = commands.pop(0), commands
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!