diff --git a/py/execnet/inputoutput.py b/py/execnet/inputoutput.py index 2d431ec62..4d80b600a 100644 --- a/py/execnet/inputoutput.py +++ b/py/execnet/inputoutput.py @@ -58,7 +58,11 @@ import sys class Popen2IO: server_stmt = """ -import sys, StringIO +import os, sys, StringIO +if sys.platform == "win32": + import msvcrt + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) io = Popen2IO(sys.stdout, sys.stdin) sys.stdout = sys.stderr = StringIO.StringIO() #try: @@ -70,10 +74,6 @@ sys.stdout = sys.stderr = StringIO.StringIO() error = (IOError, OSError, EOFError) def __init__(self, infile, outfile): - if sys.platform == 'win32': - import msvcrt - msvcrt.setmode(infile.fileno(), os.O_BINARY) - msvcrt.setmode(outfile.fileno(), os.O_BINARY) self.outfile, self.infile = infile, outfile self.readable = self.writeable = True self.lock = thread.allocate_lock() diff --git a/py/execnet/register.py b/py/execnet/register.py index 7422366d4..b08fdd6dc 100644 --- a/py/execnet/register.py +++ b/py/execnet/register.py @@ -51,6 +51,10 @@ class InstallableGateway(gateway.Gateway): class PopenCmdGateway(InstallableGateway): def __init__(self, cmd): infile, outfile = os.popen2(cmd) + if sys.platform == 'win32': + import msvcrt + msvcrt.setmode(infile.fileno(), os.O_BINARY) + msvcrt.setmode(outfile.fileno(), os.O_BINARY) io = inputoutput.Popen2IO(infile, outfile) super(PopenCmdGateway, self).__init__(io=io)