sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

IGuestSession functions do not have any return. #113

Closed XZHENDONG closed 1 year ago

XZHENDONG commented 6 years ago
ENVIRONMENT
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.

sethmlarson commented 6 years ago

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

XZHENDONG commented 6 years ago

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)
...
sethmlarson commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.

XZHENDONG commented 6 years ago

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

InvictusRMC commented 6 years ago

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() .

sethmlarson commented 6 years ago

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.

InvictusRMC commented 6 years ago

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

sethmlarson commented 1 year ago

I no longer have time to maintain this library, so am closing this issue.