简体   繁体   English

如何使用python从虚拟机读取文件

[英]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。

UPDATE 更新

>>> 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.

相关问题 如何检查虚拟机是否正在使用Python运行 - How to check if a virtual machine is running using Python 如何使用 Python 将多个文件从本地机器移动到服务器 - How to move multiple files from local machine to a sever using Python 有什么方法可以阻止 inheritance 从资源组到资源,并使用 python 对 Azure 的虚拟机磁盘应用只读锁? - Is there any way to stop the inheritance from resource group to resources and apply read-only locks to virtual machine disks of Azure using python? 使用python从virtualbox克隆现有虚拟机 - clone an existing virtual machine from virtualbox using python 使用python从虚拟机捕获实时网络流量 - Capture live network traffic from a virtual machine using python 使用Python在Azure中从磁盘创建Linux虚拟机 - Creating a linux virtual machine from disk in azure using python 如何使用python代码在Azure上创建虚拟机? - How to create a virtual machine on Azure using a python code? 如何使用python-libvirt启动具有空磁盘的虚拟机? - How to start a virtual machine with an empty disk using python-libvirt? 如何使用Python代码列出所有azure虚拟机镜像 - How to list all azure virtual machine images using Python code 如何使用Softlayer Python API重新引导虚拟机 - How to reboot a virtual machine using Softlayer Python API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM