virtualbox-python icon indicating copy to clipboard operation
virtualbox-python copied to clipboard

IGuestSession functions do not have any return.

Open XZHENDONG opened this issue 7 years ago • 9 comments

ENVIRONMENT
  • Operating System: Windows10
  • Guest OS: CentOS7 build 1511
  • Python version: 2.7.13
  • VirtualBox version: 5.2.8
  • VirtualBox SDK version:5.2.8
  • Location where VirtualBox SDK is installed: C:\Python27\Lib\site-packages\vboxapi
  • pyvbox version:1.3.2
  • [x] Happens in latest master branch?
SUMMARY

I want to run the command on my centos7 guest os and get the stdout. the command would execute on guest os but did not return.Like gs.execute('/bin/ls',['/home']),my script would block here.

And I tried to run gs.execute('/usr/bin/mkdir', ['/tmp/test']) ,the directory create success but it also no return.

other functions like makedirs() in IGuestSession are same.

STEPS TO REPRODUCE
# coding=utf-8
import virtualbox

vbox = virtualbox.VirtualBox()
vm = vbox.find_machine('centos7')

with vm.create_session() as session:
	with session.console.guest.create_session('test', 'passwd')as gs:
		process, stdout, stderr=gs.execute('/bin/ls',['/home'])
                print stdout
EXPECTED RESULTS

print stdout.

ACTUAL RESULTS

it block on the execute() function and do not have any return.

XZHENDONG avatar Apr 10 '18 17:04 XZHENDONG

Thanks for submitting this report! Can you maybe set a breakpoint within the GuestSession.execute() function and see where it's getting hung up?

sethmlarson avatar Apr 10 '18 17:04 sethmlarson

Thanks for your help!

It stops at the e = bytes(process.read(2, 65000, 0)) of the read_out() method, and keep going, I will finally trace to the site-packages\win32com\client_init.py_.It stops at DispatchBaseClass.ApplyTypes() to call self.oleobj.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args).

C:\Python27\Lib\site-packages\win32com\client\__init__.py

class DispatchBaseClass:
...
    def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
	    return self._get_good_object_(
		    self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),  ### stop here!!!
		    user, resultCLSID)
...

XZHENDONG avatar Apr 11 '18 02:04 XZHENDONG

Can you try execute(..., flags=[virtualbox.library.ProcessCreateFlag.wait_for_std_out, virtualbox.library.ProcessCreateFlag.ignore_orphaned_processes])? Might be waiting for stderr that will never write anything?

sethmlarson avatar Apr 11 '18 02:04 sethmlarson

I think I ran into this issue a while ago and ended up writing my own execute() function. I'll see if I can find the code...

sethmlarson avatar Apr 11 '18 02:04 sethmlarson

Looks like I can't find it. I would try looking at the ProcessCreateFlag.wait_for_process_start_only and try running that process asynchronously.

sethmlarson avatar Apr 11 '18 02:04 sethmlarson

I've tried not to use ProcessCreateFlag.wait_for_std_err.it would stop at o = bytes(process.read(1, 65000, 0)).Looks like the same problem.It seems that I can only try to use the vboxapi directly.Thanks

XZHENDONG avatar Apr 11 '18 02:04 XZHENDONG

Does anyone has any fix for this? I am currently facing the same issue: I try to launch the terminal on Ubuntu via execute, however my code is also hanging in the gs.execute() .

InvictusRMC avatar May 17 '18 09:05 InvictusRMC

I'll have to look into this issue, there are currently no fixes available. The best way to handle it would probably be replicating the code within GuestSession.execute() with specific flags and behaviors for your use-case.

sethmlarson avatar May 18 '18 12:05 sethmlarson

Yes I finally managed to get it working with the normal execute function when playing with the flags!

InvictusRMC avatar May 18 '18 13:05 InvictusRMC