diff options
author | James Salter <jsalter@iress.com.au> | 2015-07-17 10:56:45 +0100 |
---|---|---|
committer | James Salter <jsalter@iress.com.au> | 2015-07-17 10:56:45 +0100 |
commit | 6ea6049b762eb74135ac3069efa39dc46cfc2577 (patch) | |
tree | 72e81c5eb324a1439122d800edf54d0ab32fc805 | |
parent | a419ebb9a19be74c7ec7887eff81cf7ea0636e16 (diff) | |
download | numpy-6ea6049b762eb74135ac3069efa39dc46cfc2577.tar.gz |
don't pass un-encodable env to spawn
-rw-r--r-- | numpy/distutils/exec_command.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index f0382accc..bda20bd93 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -395,6 +395,14 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ): log.debug('Running %s(%s,%r,%r,os.environ)' \ % (spawn_command.__name__, os.P_WAIT, argv[0], argv)) + encoded_environ = {} + for k, v in os.environ.items(): + try: + encoded_environ[k.encode(sys.getfilesystemencoding())] = v.encode( + sys.getfilesystemencoding()) + except UnicodeEncodeError: + log.debug("ignoring un-encodable env entry %s", k) + argv0 = argv[0] if not using_command: argv[0] = quote_arg(argv0) @@ -412,8 +420,8 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ): else: os.dup2(fout.fileno(), se_fileno) try: - status = spawn_command(os.P_WAIT, argv0, argv, os.environ) - except OSError: + status = spawn_command(os.P_WAIT, argv0, argv, encoded_environ) + except Exception: errmess = str(get_exception()) status = 999 sys.stderr.write('%s: %s'%(errmess, argv[0])) |