passing data to subprocess.check_output

后端 未结 3 1559
醉酒成梦
醉酒成梦 2020-12-15 16:25

I want to invoke a script, piping the contents of a string to its stdin and retrieving its stdout.

I don\'t want to touch the real filesystem so I can\'t create real

3条回答
  •  悲&欢浪女
    2020-12-15 16:58

    Use Popen.communicate instead of subprocess.check_output.

    from subprocess import Popen, PIPE
    
    p = Popen([script_name, "-"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate("this is some input")
    

提交回复
热议问题