Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run_pipe_line
#1
last year i posted a 22 line version of a function to run a pipeline of multiple commands.

today i am posting a much shorter version with only 10 lines.

pipecmds.py
import subprocess
def pipecmds(*cmds,**opts):
    if not cmds:
        return
    p = []
    for cmd in cmds[:-1]:
        p.append(subprocess.Popen(cmd,stdout=subprocess.PIPE,**opts))
        opts['stdin']=p[-1].stdout
    p.append(subprocess.Popen(cmds[-1],**opts))
    return [x.wait() for x in p]
this function takes a list of the command argument strings in each function call argument for as many commands you want to run in a pipeline up to the maximum resources your hardware, system, or system administrator allows. you may use a tuple in place of any list.

if you saved the old 22 line version, please replace it or augment it with this new 10 line version.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python function run_pipe_line() Skaperen 0 2,154 Jul-03-2018, 12:42 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020