execute a command by use the COM with python directily

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
maomao
Posts: 5
Joined: 24. Mar 2014, 09:47

execute a command by use the COM with python directily

Post by maomao »

host:win7 64
guest:windows xp sp2
virtualbox:4.3.10
guestaddition:4.3.10
python:2.7.6(64 bit)

when i execute this code, something wrong in the code guestSession.processCreat(), because i can print guestSession.id
report a error "session is not in started state"

Code: Select all

vbox = win32com.client.Dispatch("VirtualBox.VirtualBox")
session = win32com.client.Dispatch("VirtualBox.Session")
mach = vbox.findMachine("wxp")
mach.lockMachine(session,1)
console = session.console
guest = console.guest
guestSession = guest.createSession("LI","","","vboxshell guest exec")
process = guestSession.processCreate("notepad.exe","C:\\Documents and Settings\\LI\\test.txt",0,1,0L)
session.UnlockMachine()
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: execute a command by use the COM with python directily

Post by noteirak »

From the SDK :
The new process will be started asynchronously, meaning on return of this function it is not guaranteed that the guest process is in a started state. To wait for successful startup, use the IProcess::waitFor call.
Are you doing this?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
maomao
Posts: 5
Joined: 24. Mar 2014, 09:47

Re: execute a command by use the COM with python directily

Post by maomao »

noteirak wrote:From the SDK :
The new process will be started asynchronously, meaning on return of this function it is not guaranteed that the guest process is in a started state. To wait for successful startup, use the IProcess::waitFor call.
Are you doing this?
maybe i don't clear this question, here i give the error i have got

Code: Select all

Traceback (most recent call last):
  File "exec_com.py", line 35, in <module>
    process = guestSession.processCreate("notepad.exe","C:\\Documents and Settin
gs\\LI\\test.txt",0,1,0L)
  File "<COMObject <unknown>>", line 2, in processCreate
pywintypes.com_error: (-2147352571, '\xc0\xe0\xd0\xcd\xb2\xbb\xc6\xa5\xc5\xe4\xa
1\xa3', None, 2)
i just try to open a txt file, but the function can't work,i'm doing something wrong?
maomao
Posts: 5
Joined: 24. Mar 2014, 09:47

Re: execute a command by use the COM with python directily

Post by maomao »

i have solve my question.
i use the IGuestSession::waitFor(), after creatSession.
thank you!
but why in the function execInGuest of vboxshell.py (come from the SDK) ,do not use the IGuestSession::waitFor(), i was mislead by it.
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: execute a command by use the COM with python directily

Post by noteirak »

For the why, you would need to ask the developers directly on the dev mailing list - it's a design choice more than anything.
My guess is that you don't want to impose something like waiting an arbitrary amount of time.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply