From ad7307b927aaf81f3e03e1adf46eec099191eb4f Mon Sep 17 00:00:00 2001 From: "Seth M. Larson" Date: Wed, 3 May 2017 21:54:12 -0500 Subject: [PATCH 1/2] Fix IGuestProcess.execute() on Python 3 ... ... where stdout and stderr are of type `memoryview` and `str(memoryview)` turns to `''`. --- virtualbox/library_ext/guest_session.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/virtualbox/library_ext/guest_session.py b/virtualbox/library_ext/guest_session.py index c4801a4..9dbe786 100644 --- a/virtualbox/library_ext/guest_session.py +++ b/virtualbox/library_ext/guest_session.py @@ -45,11 +45,15 @@ def execute(self, command, arguments=[], stdin="", environment=[], def read_out(process, flags, stdout, stderr): if library.ProcessCreateFlag.wait_for_std_err in flags: process.wait_for(int(library.ProcessWaitResult.std_err)) - e = str(process.read(2, 65000, 0)) + e = process.read(2, 65000, 0) + if isinstance(e, memoryview): + e = bytes(e) stderr.append(e) if library.ProcessCreateFlag.wait_for_std_out in flags: process.wait_for(int(library.ProcessWaitResult.std_out)) - o = str(process.read(1, 65000, 0)) + o = process.read(1, 65000, 0) + if isinstance(o, memoryview): + o = bytes(o) stdout.append(o) process = self.process_create_ex(command, @@ -85,7 +89,7 @@ def read_out(process, flags, stdout, stderr): # make sure we have read the remainder of the out read_out(process, flags, stdout, stderr) - return process, "".join(stdout), "".join(stderr) + return process, b"".join(stdout), b"".join(stderr) def makedirs(self, path, mode=0x777): "Super-mkdir: create a leaf directory and all intermediate ones." From 236e5b4b818922629c1fe98bad34f5fd80794c27 Mon Sep 17 00:00:00 2001 From: "Seth M. Larson" Date: Wed, 3 May 2017 22:03:24 -0500 Subject: [PATCH 2/2] Might as well always used bytes() --- virtualbox/library_ext/guest_session.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/virtualbox/library_ext/guest_session.py b/virtualbox/library_ext/guest_session.py index 9dbe786..a933355 100644 --- a/virtualbox/library_ext/guest_session.py +++ b/virtualbox/library_ext/guest_session.py @@ -45,15 +45,11 @@ def execute(self, command, arguments=[], stdin="", environment=[], def read_out(process, flags, stdout, stderr): if library.ProcessCreateFlag.wait_for_std_err in flags: process.wait_for(int(library.ProcessWaitResult.std_err)) - e = process.read(2, 65000, 0) - if isinstance(e, memoryview): - e = bytes(e) + e = bytes(process.read(2, 65000, 0)) stderr.append(e) if library.ProcessCreateFlag.wait_for_std_out in flags: process.wait_for(int(library.ProcessWaitResult.std_out)) - o = process.read(1, 65000, 0) - if isinstance(o, memoryview): - o = bytes(o) + o = bytes(process.read(1, 65000, 0)) stdout.append(o) process = self.process_create_ex(command,