Extending a shell in a Python subprocess

Possible duplicate:
Python subprocess subprocess

Using Python 2.6 subprocess module, I need to run a command in the src.rpm file that I create with the previous subprocess call.

Unfortunately, I'm working with spec files that are incompatible, so I only have a vague idea of ​​what the src.rpm filename should look like (for example, I know the package name and extension to something named "{package} - {version } .src.rpm ", but not the version).

I know, however, that I will only have one src.rpm file in the directory I am looking for, so I can invoke mock with a command like

mock {options} *.src.rpm

and work in a shell, but the subprocess doesn't seem to want to accept the expansion. I tried using (shell = True) as an argument for subprocess.call (), but even if it worked, I would rather avoid it.

How do I get something like

subprocess.call("mock *.src.rpm".split())

for start?

+3


source to share


2 answers


Use the package glob

:



import subprocess    
from glob import glob
subprocess.call(["mock"] + glob("*.src.rpm"))

      

+6


source


The wildcard * must be interpreted by SHELL. When you run subprocess.call, it doesn't load the shell by default, but you can give it shell=True

as an argument:



subprocess.call("mock *.src.rpm".split(), shell=True)

      

+3


source