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?
FIRST it’s not regular expression it’s shell expansion (glob) that you seem to want to execute. Which means that you should invoke /bin/sh to execute cat. The following should do the trick:
Now /bin/sh will actually perform the asterisk expansion for you and you’ll get the desired result.
Or you can use globbing library to do globbing expansions yourself (i.e. do the work that shell does):
glob.glob() returns the array of files that match the globbing.