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