As Pulkit pointed out, I and Pulkit made another version in parallel. https://patchwork.mercurial-scm.org/patch/47937/ https://patchwork.mercurial-scm.org/patch/47938/ https://patchwork.mercurial-scm.org/patch/47939/ `sys.std*` are left unmodified. `procutil.std*` are fixed up to raise EBADF.