Run a python script in the guest virtual machine using vmrun runScriptInGuest

4.7k views Asked by At

I am trying to run a very long python script which resides in guest virtual machine A.py from the host linux machine. The guest VM is Windows 7x64 and application is VMware Fusion.

I am using following command:

vmrun -T ws -gu <username> -gp <password> runScriptInGuest "/Users/userdir/Documents/Virtual Machines.localized/Windows7x64.vmwarevm/Windows7x64.vmx" C:\\Users\\Admin\\Documents\\A.py C:\Python27\python.exe

This is not working. Any ideas on how to get this working?

I really appreciate your help.

3

There are 3 answers

1
vikramls On BEST ANSWER

Just a wild guess, but try changing the order of the last 2 arguments:

vmrun -T ws -gu -gp runScriptInGuest "/Users/userdir/Documents/Virtual Machines.localized/Windows7x64.vmwarevm/Windows7x64.vmx" C:\Python27\python.exe C:\Users\Admin\Documents\A.py 

The Python interpreter should be invoked by the VM and the interpreter will run the A.py script.

2
internalerror404 On
vmrun -T ws -gu Admin -gp Apple1984 runProgramInGuest "/Users/userdir/Documents/Virtual Machines.localized/Windows7x64.vmwarevm/Windows7x64.vmx" -activeWindow "C:\Users\\Admin\A.bat"

where A.bat is a bat file where I invoke python script

@echo off
cd C:\Users\Admin
C:\python27\python.exe A.py %*
0
THAVASI.T On

try the pip module. vmrunPacked this pkg use to vm take control. start, stop, snapshot create, revert, delete. inside file run. both of all execute.

vmrunPacked tool use run the A.py script

pip install vmrunPacked

install this package

import vmrunPacked
#assgin vm object
vmobj = vmrunPacked.Pack("/vmx_file_path/vm.vmx",userName="admin",passWord="admin@123")

# start the vm
vmobj.start()

# run the ruby script file in inside vm
interpreter_path = "C:\\Program Files\\Ruby\\ruby.exe"
file_path = "D:\\new\\init.rb"
vmobj.run_script_in_guest(interpreter_path, file_path)

read the document vmrunPacked