How do I pass a string into subprocess.Popen (using the stdin argument)?

后端 未结 11 2995
半阙折子戏
半阙折子戏 2020-11-22 01:33

If I do the following:

import subprocess
from cStringIO import StringIO
subprocess.Popen([\'grep\',\'f\'],stdout=subprocess.PIPE,stdin=StringIO(\'one\\ntwo\\         


        
11条回答
  •  眼角桃花
    2020-11-22 02:05

    Apparently a cStringIO.StringIO object doesn't quack close enough to a file duck to suit subprocess.Popen

    I'm afraid not. The pipe is a low-level OS concept, so it absolutely requires a file object that is represented by an OS-level file descriptor. Your workaround is the right one.

提交回复
热议问题