gexec in vboxshell.py does not appear to work

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
nimchimsky
Posts: 3
Joined: 27. Jul 2015, 14:29
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: CentOS 7.1

gexec in vboxshell.py does not appear to work

Post by nimchimsky »

Anyone else having problems getting gexec in vboxshell.py to work? I had to add a wait loop in line 1119 to wait for session to start, and further down also another line to wait for process to start.

Code: Select all

   # Excerpt code starting with line 1118 in /Applications/VirtualBox.app/Contents/MacOS/vboxshell.py (VBox v5.0)
    guestSession = guest.createSession(user, passwd, "", "vboxshell guest exec")
    while guestSession.status != ctx['global'].constants.GuestSessionStatus_Started: time.sleep(0.1)
    # shall contain program name as argv[0]
    gargs = args
    print "executing %s with args %s as %s" % (args[0], gargs, user)
    flags = 0
    if inputPipe is not None:
        flags = 1 # set WaitForProcessStartOnly
    print args[0]
    process = guestSession.processCreate(args[0], gargs, env, [], tmo)
    while process.status != ctx['global'].constants.ProcessStatus_Started: time.sleep(0.1)
Now the test command (gexec <vmname> hostname) just hangs. Any ideas?
Thanks.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: gexec in vboxshell.py does not appear to work

Post by noteirak »

Are you sure gexec is not waiting for stdin? the process would never end in this case...
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
nimchimsky
Posts: 3
Joined: 27. Jul 2015, 14:29
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: CentOS 7.1

Re: gexec in vboxshell.py does not appear to work

Post by nimchimsky »

Hi @noteirak , thanks for your response.

The test command I'm running shouldn't require stdin. It's just running 'hostname' on the CentOS 7 VM, and should just come back with the name ("c2"). Right now it's coming back immediately with this error:

Code: Select all

vbox> gexec c2 hostname
executing hostname with args ['hostname'] as root
hostname
executed with pid 0
global name 'progress' is not defined
vbox>
I guess what I'm saying is that gexec in vboxshell.py doesn't appear to be completed and working out of the box. Do you or anyone in this forum have a working Python example of IGuestSession processCreate?

@noteirak, I have read your comments in viewtopic.php?f=34&t=66287 , and understand that there are some busy/wait tricks we have to do to get things to work properly. At any rate, I think it would be really useful for everyone if vboxshell.py/gexec was working out of the box, so it can easily be used as an example.

Right now, after my changes, it appears that variables progress and pid are not even defined properly :(

Thanks in advance,
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: gexec in vboxshell.py does not appear to work

Post by noteirak »

I'm not aware of someone having working code. I'll have a look at the sample code tomorrow, see if there's indeed an issue. I'll let the devs known if that's the case. Stay tuned!
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: gexec in vboxshell.py does not appear to work

Post by noteirak »

After checking with the devs, the script is not actively maintained, so breakage is not surprising after years of subtle changes in the API. Don't hold your breath for a fix.
If you manage to fix it, contributions are most welcome of course!
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
nimchimsky
Posts: 3
Joined: 27. Jul 2015, 14:29
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: CentOS 7.1

Re: gexec in vboxshell.py does not appear to work

Post by nimchimsky »

Bummer. Thanks.

For those who may find this useful, one problem is that API v5.0 changed the way processCreate accepts arguments. It now requires that the file you're trying to execute also needs to be included in the list of arguments (evidently previous API versions didn't require this):

Code: Select all

...
procFile = "/bin/hostname"
procArgs = [procFile]
if int(apiver[0]) < 5: procArgs = procArgs[1:]  # Note API v5.0 change
procEnv   = []
procFlags = [const.ProcessCreateFlag_None]
timeOut   = 0  # Wait indefinitely
guestProc = guestSession.processCreate(procFile, procArgs, procEnv, procFlags, timeOut)
...
Post Reply