execute shell script from python, needs sys.argv

Tim Roberts timr at probo.com
Sat Nov 6 18:53:48 EDT 2010


Benjamin Kaplan <benjamin.kaplan at case.edu> wrote:
>
>Python is not the shell. Shell commands are not python commands. You
>need either a string or a list of strings, so any literal have to be
>in quotes. Also, subprocess can't handle the redirection. You need to
>run it as two commands.
>
>proc1 = subprocess.Popen(["cat", sys.argv[1]],stdout =
>subprocess.PIPE, shell = True)
>proc2 = subprocess.Popen(["fastx_trimmer", "-n", "COUNT", "-o",
>sys.argv[2]],stdin=proc1.stdout, shell=True)

I KNOW that we're still working on syntax here, and that it's too early for
optimization, but it bothers me to see "cat" as the first thing in a
pipeline.  You don't actually need two steps here at all:

  proc1 = subprocess.Popen(
      ["fastx_trimmer", "-n", "COUNT", "-o", sys.argv[2],
      stdin=open(sys.argv[1]), shell=True
  )

With this, I don't think you even need "shell=True".
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list