#!/usr/bin/python3 -BEOObbs # coding=utf-8 import subprocess, sys file = open('test.txt', 'bw') file.write(b'1\n') file.close() pipe = subprocess.Popen(['diff', '-u', 'test.txt', '-'], stderr = subprocess.PIPE, stdin = subprocess.PIPE, stdout = subprocess.PIPE) pipe.stdin.write(b'2\n') pipe.stdin.flush() #pipe.stdin.close() print(pipe.stdout.read().decode()) pipe.wait()