recursive grep using python

后端 未结 4 954
萌比男神i
萌比男神i 2020-12-11 07:55

I am new to python and trying to learn. I am trying to implement a simple recursive grep using python for processing and here is what I came to so far.

p =          


        
4条回答
  •  眼角桃花
    2020-12-11 08:15

    Maybe an example can help you, the command find . -print | grep "python" is equivalent to this:

    import subprocess
    
    pc1 = subprocess.Popen('find . -print', stdout=subprocess.PIPE, shell=True)
    pc2 = subprocess.Popen('grep "python"', stdin=pc1.stdout, shell=True,
                           stdout=subprocess.PIPE)
    
    print pc2.communicate()[0]
    

提交回复
热议问题