0

I am new to python, I want to call grep unix command on some file with some specific switches, but not able to get the output. Seems the * (globbing) is creating some problem

Below is working, and gives the grep output

>>> import subprocess
>>> subprocess.call('ls')
1-intro.txt  2-data-types.txt  3-numbers-integers.txt  4-strings.txt  data-chap1.txt
0
>>> cmd = ["grep", "-i", "string", "1-intro.txt" ]
>>> subprocess.call(cmd)
strings
0

Problem, when I give * as param to grep

>>> cmd = ["grep", "-i", "string", "*.txt" ]
>>> subprocess.call(cmd)
grep: *.txt: No such file or directory
2

I replaced the 1-intro.txt with *.txt. Can you please let me know, what am I doing wrong? Why isn't the 2nd part working?

Note: Python 2.4.3

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
mtk
  • 13,221
  • 16
  • 72
  • 112
  • See also [Python Subprocess Grep](http://stackoverflow.com/q/7956865/4279) – jfs Apr 01 '14 at 12:38
  • btw, you could use `glob.glob()`, `os.path.expanduser()`, `os.listdir('.')`, etc instead of `shell=True` – jfs Apr 01 '14 at 12:39

0 Answers0