How can I invoke a shell command from python which includes regexp (i.e., cat filename*).
I wrote:
pid = subprocess.Popen(["cat", filename + "*"])
but I am getting an error
cat filename* no such file or directory.
I'd like to force the shell to treat "*" as a regexp and not as a string. Is there any way to implement this?
Use an underlying shell to expand your globs:
pid = subprocess.Popen(["cat",filename+"*"], shell=True)
Alternatively, use glob.glob to expand your arguments before running the command:
import glob
pid = subprocess.Popen(["cat"] + glob.glob(filename + "*"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With