Use StringIO as stdin with Popen

前端 未结 2 2126
抹茶落季
抹茶落季 2020-12-16 14:38

I have the following shell script that I would like to write in Python (of course grep . is actually a much more complex command):

#!/bin/bash

         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 15:00

    p = subprocess.Popen(['grep', '...'], stdin=subprocess.PIPE, 
                                          stdout=subprocess.PIPE)
    output, output_err = p.communicate(myfile.read())
    

提交回复
热议问题