]> arthur.barton.de Git - bup.git/blobdiff - cmd/bup
bup: use correct bup executable in on--server
[bup.git] / cmd / bup
diff --git a/cmd/bup b/cmd/bup
index 4b5097d5a2cf7b2c2801b3fe665844ea9baa57a0..e8462dffdb406ac2db6909a09ab38ebe14908f62 100755 (executable)
--- a/cmd/bup
+++ b/cmd/bup
@@ -16,21 +16,23 @@ exec "$script_home/bup-python" "$0" ${1+"$@"}
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
-import errno, re, sys, os, subprocess, signal, getopt
+import errno, getopt, os, re, select, signal, subprocess, sys
+from subprocess import PIPE
+
+from bup.compat import environ, restore_lc_env
 
 if sys.version_info[0] != 2 \
-   and not os.environ.get('BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == 'true':
+   and not environ.get(b'BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == b'true':
     print('error: bup may crash with python versions other than 2, or eat your data',
           file=sys.stderr)
     sys.exit(2)
 
-from subprocess import PIPE
-from sys import stderr, stdout
-import select
+restore_lc_env()
 
 from bup import compat, path, helpers
 from bup.compat import add_ex_tb, add_ex_ctx, wrap_main
 from bup.helpers import atoi, columnate, debug1, log, merge_dict, tty_width
+from bup.io import byte_stream
 
 cmdpath = path.cmddir()
 
@@ -222,11 +224,15 @@ def run_subcmd(subcmd):
     if not (fix_stdout or fix_stderr):
         os.execvp(c[0], c)
 
+    sys.stdout.flush()
+    sys.stderr.flush()
+    out = byte_stream(sys.stdout)
+    err = byte_stream(sys.stderr)
     p = None
     try:
         p = subprocess.Popen(c,
-                             stdout=PIPE if fix_stdout else sys.stdout,
-                             stderr=PIPE if fix_stderr else sys.stderr,
+                             stdout=PIPE if fix_stdout else out,
+                             stderr=PIPE if fix_stderr else err,
                              env=tty_env, bufsize=4096, close_fds=True)
         # Assume p will receive these signals and quit, which will
         # then cause us to quit.
@@ -235,8 +241,8 @@ def run_subcmd(subcmd):
 
         filter_output(fix_stdout and p.stdout.fileno() or None,
                       fix_stderr and p.stderr.fileno() or None,
-                      fix_stdout and sys.stdout.fileno() or None,
-                      fix_stderr and sys.stderr.fileno() or None)
+                      fix_stdout and out.fileno() or None,
+                      fix_stderr and err.fileno() or None)
         return p.wait()
     except BaseException as ex:
         add_ex_tb(ex)