diff --git a/mssql-scripter b/mssql-scripter index e7b9c26..8774054 100644 --- a/mssql-scripter +++ b/mssql-scripter @@ -8,6 +8,9 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +# Set the python io encoding to UTF-8 by default if not set. +if [ -z ${PYTHONIOENCODING+x} ]; then export PYTHONIOENCODING=utf8; fi + export PYTHONPATH="${DIR}:${PYTHONPATH}" python -m mssqlscripter "$@" diff --git a/mssql-scripter.bat b/mssql-scripter.bat index ad40c04..20df872 100644 --- a/mssql-scripter.bat +++ b/mssql-scripter.bat @@ -1,6 +1,9 @@ @echo off setlocal - +REM Set the python io encoding to UTF-8 by default if not set. +IF "%PYTHONIOENCODING%"=="" ( + SET PYTHONIOENCODING="UTF-8" +) SET PYTHONPATH=%~dp0;%PYTHONPATH% python -m mssqlscripter %* diff --git a/mssqlscripter/main.py b/mssqlscripter/main.py index 5c01858..558e46c 100644 --- a/mssqlscripter/main.py +++ b/mssqlscripter/main.py @@ -26,7 +26,6 @@ logger = logging.getLogger(u'mssqlscripter.main') def main(args): """ Main entry point to mssql-scripter. - """ scripterlogging.initialize_logger() logger.info('Python Information :{}'.format(sys.version_info)) @@ -96,13 +95,6 @@ def main(args): if temp_file_path: with io.open(parameters.FilePath, encoding=u'utf-16') as script_file: for line in script_file.readlines(): - # If piping, stdout encoding is none in python 2 which resolves to 'ascii'. - # If it is not none then the user has specified a custom - # encoding. - if not sys.stdout.encoding: - # We are piping and the user is using the default encoding, - # so encode to utf8. - line = line.encode(u'utf-8') sys.stdout.write(line) finally: