How to run scripts in guest machines

Discussion in 'General Questions' started by LynnO, Sep 16, 2011.

  1. LynnO

    LynnO

    Messages:
    28
    I'm making the transition from VMware Fusion to Parallels 7. On Fusion I had a build script set up on the host that ran a build script in each of three guests: WinXP; Win7; OS X Lion, returning the status of each step. Other than the Remote Desktop Access API, which looks more than a little cumbersome to me (e.g. how would I create screen captures to deal with all possible error conditions?), the only approach I can think of is to create standalone programs that are exposed through coherence, and run those from the host.

    However, coherence isn't supported for OS X.

    Fusion provides a simple utility that allows you to start a program in a VM, set and read variables, and a few other things. Is there anything similar available for Parallels? Is there another approach available that might work?
     
  2. STim

    STim Super Moderator

    Messages:
    942
    There is no official way to do this in PDfM. However, you may try prlctl exec command:
    Code:
    prlctl exec <VM ID|Name> <command>
    It may not work with OSX guest though... But you could workaround it using ssh from host to guest.

    Can you point me to some reading about this Fusion way to run scripts?
     
  3. LynnO

    LynnO

    Messages:
    28
    You are right, the prlctl exec command looks promising. I'm not familiar with ssh, so I'll have to study up on how to set it up. Thanks for the good suggestions.

    The document for vmrun is at http://www.vmware.com/pdf/vix160_vmrun_command.pdf

    I can post some python fragments if you want to see examples.
     
  4. LynnO

    LynnO

    Messages:
    28
    It looks like VmGuest.run_program might do what I want as well, if that is available to the host machine. All of my current scripts are written in Python anyway.
     
  5. LynnO

    LynnO

    Messages:
    28
    "prlctl exec vm name cmd" works for the Windows guests; "prlctl exec OS X vm name /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal" works in the OS X guest.

    So it looks like I have a path forward, regardless of how well the Python API works.

    Edit: I've installed the Virtualiztion SDK in order to investigate the Python APIs. The main package: prlsdkapi is missing after the install, so I didn't get very far. Anyone know how to find prlsdkapi?
     
    Last edited: Sep 16, 2011
  6. LynnO

    LynnO

    Messages:
    28
    Here is the code I am using to try and execute a program in a Windows XP VM (vm is set earlier by call to search_vm()):
    Code:
        guest = prlsdkapi.VmGuest(vm.handle)
        
        hArgsList = prlsdkapi.StringList()
        hArgsList.add_item("www.google.com")
        hEnvsList = prlsdkapi.StringList()
        hEnvsList.add_item("")
        
        guest.run_program("iexplore.exe", hArgsList, hEnvsList)
    This takes me to prlsdkapi/__init__.py line 4641:
    Code:
    4637 	def run_program(self, sAppName, hArgsList, hEnvsList, nFlags = consts.PRPM_RUN_PROGRAM_AND_RETURN_IMMEDIATELY, nStdin = consts.PRL_INVALID_FILE_DESCRIPTOR, nStdout = consts.PRL_INVALID_FILE_DESCRIPTOR, nStderr = consts.PRL_INVALID_FILE_DESCRIPTOR):
    4638  		"""
    4639  		Execute a program in a virtual machine.
    4640  		"""
    4641  		return Job(SDK.PrlVmGuest_RunProgram(self.handle, sAppName, conv_handle_arg(hArgsList), conv_handle_arg(hEnvsList), nFlags, nStdin, nStdout, nStderr)[0])
    Next I see two calls to conv_handle_arg(), as expected, and then it goes to prlsdkapi/__init__.py line 227:
    Code:
    224  class _Handle(object):
    225
    226    	def __init__(self, handle = consts.PRL_INVALID_HANDLE):
    227     	self.handle = handle
    228    	 	self.id = deinit_sdk.id
    229    		if self.__class__ is _Handle:
    230    			raise TypeError, 'class _Handle is a private class'
    And returns after line 229. I can't trace through the actual call to SDK.PrlVmGuest_RunProgram, which resolves to:

    Code:
    SDK = <module 'prlsdkapi.prlsdk' from '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/prlsdkapi/prlsdk.so'>
    I see nothing happening in the guest, and the return from the run_program() call is immediate. Any suggestions?

    Edit: In addition to the default (PRPM_RUN_PROGRAM_AND_RETURN_IMMEDIATELY) I also tried:
    PRPM_RUN_PROGRAM_ENTER -- return from function call is still immediate
    PRPM_RUN_PROGRAM_IN_SHELL
     
    Last edited: Sep 19, 2011

Share This Page