可以办到.但是,从Python 2.5开始,这种机制是特定于Linux的,不可移植:
import subprocess import sys file = sys.argv[1] p1 = subprocess.Popen(['hg', 'cat', file], stdout=subprocess.PIPE) p2 = subprocess.Popen([ 'gvimdiff', '/proc/self/fd/%s' % p1.stdout.fileno(), file]) p2.wait()
也就是说,在diff的特定情况下,您可以简单地从stdin获取其中一个文件,并且无需使用与bash相同的功能:
file = sys.argv[1] p1 = subprocess.Popen(['hg', 'cat', file], stdout=subprocess.PIPE) p2 = subprocess.Popen(['diff', '-', file], stdin=p1.stdout) diff_text = p2.communicate()[0]