From e3124e1b581e30579c974e7be567e850cad5a6d6 Mon Sep 17 00:00:00 2001 From: Thesharing Date: Sun, 18 Nov 2018 00:53:09 +0800 Subject: [PATCH] Make _exec_with_pipe function compatible with Windows --- execjs/_external_runtime.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/execjs/_external_runtime.py b/execjs/_external_runtime.py index 2b05c16..cbc5f9f 100644 --- a/execjs/_external_runtime.py +++ b/execjs/_external_runtime.py @@ -96,17 +96,15 @@ def _exec_with_pipe(self, source): p = None try: - p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=self._cwd, universal_newlines=True) - input = self._compile(source) - if six.PY2: - input = input.encode(sys.getfilesystemencoding()) + p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=self._cwd, universal_newlines=False) + input = self._compile(source).encode(sys.getdefaultencoding()) stdoutdata, stderrdata = p.communicate(input=input) ret = p.wait() finally: del p self._fail_on_non_zero_status(ret, stdoutdata, stderrdata) - return stdoutdata + return stdoutdata.decode(sys.getdefaultencoding()) def _exec_with_tempfile(self, source): (fd, filename) = tempfile.mkstemp(prefix='execjs', suffix='.js')