How to run python script inside of my vm?

2,520 views
Skip to first unread message

mickey shmueli

unread,
May 24, 2012, 6:19:32 AM5/24/12
to pysphere
Hey I am trying to run python scripts inside of my vmware with
pysphere....
I have tried to just execute the script( vm.start_process(r"c:
\my.py"), and I got a an error "VIApiException: [SystemErrorFault]: A
general system error occurred: A program c
ould not run on the guest operating system"
I have tried to run the python.exe with an argument that is the
script(vm.start_process(PYTHONPATH,args=[" -c print'hey'"])). and it
didn't the only that happened was the python interactive window
opened.
I have tried to run "cmd.exe" and give as an argument the python.exe
and the script that i want to run in the command line, it did not work
as well, the cmd.exe window opened.
I managed to run the script by writing a bat file that runs the python
file but this solution looks really crooked to me.
right now i am out ideas do you have any idea that uses PySphere
only?

I thought about using RPYC, but it means that i need to make sure in
every setup that the server is up ...

Seba

unread,
Jun 1, 2012, 8:33:17 AM6/1/12
to pysphere
Hi Mickey,

The following is working right for me:

1) On the guest machine (a windows XP) I ve got python 2.7 installed.
And I've got the following python script file
C:\Document and Settings\admin\Desktop\test.py

#### FILE CONTENT ####
import os
print "Current working directory is:", os.getcwd()

fd = open("test.txt", "w")
fd.write("hola mundo")
fd.close()
raw_input() #wait for a key so the windows is not closed
#### EOF ####

2) From pysphere I run the following
> vm.login_in_guest("admin", "secret")
> vm.start_process(r"c:\python27\python.exe", args=[r"c:\Documents and Settings\admin\desktop\test.py"])

That's working fine, however the script prints:
"Current working directory is: C:\windows\System32"
and the file test.txt is created on that directory too

So instead, I want to do this:
> vm.start_process(r"c:\python27\python.exe", args=["test.py"], cwd=r"c:\Documents and Settings\admin\desktop")

Which will print "c:\Documents and Settings\admin\desktop" as working
directory, and will place the test.txt file on that directory too


Hope that helps,


Regards,

Seba.
Reply all
Reply to author
Forward
0 new messages