From 8f6652dbef562a5b0f865085941d5a5095d8babc Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 2 Aug 2018 22:05:42 -0400 Subject: [PATCH 1/4] set stdout to binary mode on windows --- lib/extensions/output.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/extensions/output.py b/lib/extensions/output.py index 1dc8d19d5..e72eac7bd 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -36,6 +36,10 @@ class Output(InkstitchExtension): write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot()) + if sys.platform == "win32": + import msvcrt + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) + # inkscape will read the file contents from stdout and copy # to the destination file that the user chose with open(temp_file.name) as output_file: From b7c5a594ddded90c6ff9233825ac280aa7eb0367 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 3 Aug 2018 21:50:54 -0400 Subject: [PATCH 2/4] debug --- lib/extensions/output.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/extensions/output.py b/lib/extensions/output.py index e72eac7bd..bae0998cf 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -37,6 +37,7 @@ class Output(InkstitchExtension): write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot()) if sys.platform == "win32": + print >> sys.stderr, "setting stdout to binary mode" import msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) @@ -44,6 +45,7 @@ class Output(InkstitchExtension): # to the destination file that the user chose with open(temp_file.name) as output_file: sys.stdout.write(output_file.read()) + sys.stdout.flush() # clean up the temp file os.remove(temp_file.name) From 782b5efc71ab63a6becd7aa846feed5ea48a678a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 3 Aug 2018 22:11:13 -0400 Subject: [PATCH 3/4] read in binary too --- lib/extensions/output.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/extensions/output.py b/lib/extensions/output.py index bae0998cf..f3bb0a802 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -37,13 +37,12 @@ class Output(InkstitchExtension): write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot()) if sys.platform == "win32": - print >> sys.stderr, "setting stdout to binary mode" import msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) # inkscape will read the file contents from stdout and copy # to the destination file that the user chose - with open(temp_file.name) as output_file: + with open(temp_file.name, "rb") as output_file: sys.stdout.write(output_file.read()) sys.stdout.flush() From 89e5e5c9dbc036be1e0c2802e2324216c6a9ff0a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 3 Aug 2018 22:39:52 -0400 Subject: [PATCH 4/4] stub should also open stdout in binary mode --- stub.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stub.py b/stub.py index 850cfe404..6cd980cb9 100644 --- a/stub.py +++ b/stub.py @@ -33,6 +33,10 @@ args[0] = binary_path extension = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = extension.communicate() +if sys.platform == "win32": + import msvcrt + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) + stdout = stdout.strip() if stdout: print stdout.strip(),