[英]How to read files from a virtual machine using python
I'm running a virtual machine on my system using Oracle VirtualBox , what i'm trying to accomplish is to read file on virtual machine from my physical system . 我正在使用Oracle VirtualBox在系统上运行虚拟机,我要完成的工作是从物理系统读取虚拟机上的文件。 i'm using virtualbox api (pyvbox) to interface with VirtualBox .
我正在使用virtualbox api(pyvbox)与VirtualBox进行交互。 This the first time i'm using a virtualbox api.
这是我第一次使用virtualbox api。
>>> import virtualbox
>>> vbox = virtualbox.VirtualBox()
>>> vm =vbox.find_machine("XPBox")
>>> session = vm.create_session()
>>> gs = session.console.guest.create_session('xphandler' , ' qwerty')
>>> process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
File "C:\Python27\lib\site-packages\virtualbox\library_ext\guest_session.py", line 54, in execute
process.wait_for(int(library.ProcessWaitResult.start), 0)
File "C:\Python27\lib\site-packages\virtualbox\library.py", line 13666, in wait_for
reason = ProcessWaitResult(reason)
File "C:\Python27\lib\site-packages\virtualbox\library.py", line 121, in __init__
raise ValueError("Can not find enumeration where value=%s" % value)
ValueError: Can not find enumeration where value=None
>>>
This is the output when i type the below given solution. 这是我键入以下给定解决方案时的输出。
Read the pyvbox documentation carefully. 请仔细阅读pyvbox文档。 I believe you can figure out some solution.
我相信您可以找到一些解决方案。 The given below example from the doc is not what you want but a good reference to start up.
doc中给出的以下示例不是您想要的,而是一个很好的启动参考。
ipython
In [1]: import virtualbox
In [2]: vbox = virtualbox.VirtualBox()
In [3]: vm = vbox.find_machine('test_vm')
In [4]: session = vm.create_session()
In [5]: gs = session.console.guest.create_session('Name', 'password')
In [6]: process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
In [7]: print stdout
Here is an example on how to copy from a guest VM: https://gist.github.com/mjdorma/9044686 这是有关如何从来宾VM复制的示例: https : //gist.github.com/mjdorma/9044686
The traceback you posted seems to happen to a number of users. 您发布的回溯似乎发生在许多用户身上。 It occurs when IProcess.wait_for returns None.
当IProcess.wait_for返回无时,会发生这种情况。 The library attempts to enumerate what type of ProcessWaitResult has been returned.
该库尝试枚举已返回哪种类型的ProcessWaitResult。 This happens when vboxapi returns None from an attempted call to the IProcess.wait_for COM interface.
当vboxapi尝试调用IProcess.wait_for COM接口返回None时,就会发生这种情况。
In [5]: virtualbox.library.IProcess.wait_for?
Type: instancemethod
String Form:<unbound method IProcess.wait_for>
File: virtualbox\library.py
Definition: virtualbox.library.IProcess.wait_for(self, wait_for, timeout_ms)
Docstring:
Waits for one or more events to happen.
in wait_for of type int
Specifies what to wait for;
see <link to="ProcessWaitForFlag"/> for more information.
in timeout_ms of type int
Timeout (in ms) to wait for the operation to complete.
Pass 0 for an infinite timeout.
return reason of type ProcessWaitResult
The overall wait result;
see <link to="ProcessWaitResult"/> for more information.
Tip: Ensure you are running the latest virtualbox release when operating pyvbox. 提示:确保在运行pyvbox时正在运行最新的virtualbox版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.