2 from __future__ import absolute_import
3 import os, subprocess, sys
5 from bup import options
6 from bup.helpers import debug1, debug2, mux
7 from bup.io import byte_stream
11 bup mux command [arguments...]
16 # Give the subcommand exclusive access to stdin.
17 orig_stdin = os.dup(0)
18 devnull = os.open(os.devnull, os.O_RDONLY)
22 o = options.Options(optspec)
23 opt, flags, extra = o.parse_bytes(argv[1:])
25 o.fatal('command is required')
29 debug2('bup mux: starting %r\n' % (extra,))
31 outr, outw = os.pipe()
32 errr, errw = os.pipe()
37 p = subprocess.Popen(subcmd, stdin=orig_stdin, stdout=outw, stderr=errw,
38 close_fds=False, preexec_fn=close_fds)
42 out = byte_stream(sys.stdout)
45 mux(p, out.fileno(), outr, errr)
51 debug1('%s exited with code %d\n' % (extra[0], prv))
53 debug1('bup mux: done\n')