4

Environment presentation:

  • Host Machine: Ubuntu 12.04 LTS
  • Guest Machine: Ubuntu 12.04 LTS. Inside this VM, a my_program.py exists.

  • Virtualization system: VirtualBox 4.3

Question:

Is there any way to launch my_program.py from the host machine ?

Takkat
  • 142,284
  • 1
    The existing answer does not give enough details on how to launch a guest script. I see you had accepted it. It would therefore be great if you added your steps to launch the Python script either by an edit to the accepted answer, or by writing this up in your own answer. – Takkat Jul 02 '14 at 09:56
  • @Takkat Yes, it does not show me how to code (script) that. But I thought I will try to do it in future days ... unless if someone does it here :) –  Jul 02 '14 at 10:07
  • 2
    Well, for future visitors it helps tremendously if we only accept answers that were tested to work without issues. – Takkat Jul 02 '14 at 10:13
  • 1
    @Takkat I had assumed that the user was sufficiently advanced to be able to follow through the manuals on this subject – Charles Green Jul 03 '14 at 12:53
  • @CharlesGreen I thought I would use your information later when I reach this point (in few days) by scripting something around it. As Takkat said, I would wait a little bit before accepting the answser. –  Jul 03 '14 at 12:56
  • 1
    @begueradj I didn't think I'd really need to hold your hand through the process, as you are able to create a VM, and an operable script :) – Charles Green Jul 03 '14 at 13:03
  • begueradj why the bounty? Did @CharlesGreen answer not help? – muru Jul 25 '14 at 20:04
  • @muru I did not succeed to fabricate something that functions even if he gave me the right information. –  Jul 25 '14 at 20:08
  • What error did you get? Have you installed the Guest Additions as CharlesGreen said? – muru Jul 25 '14 at 20:18
  • 2
    The answer of @CharlesGreen works. You could also just install ssh-server on the guest and ssh in. – bain Jul 25 '14 at 22:00

2 Answers2

6

You can use Vboxmanage to do this. The form of the command is

VBoxManage guestcontrol <uuid|vmname> exec[ute]
            --image <path to program> --username <name>
            [--passwordfile <file> | --password <password>]
            [--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"]
            [--verbose] [--timeout <msec>]
            [--wait-exit] [--wait-stdout] [--wait-stderr]
            [--dos2unix] [--unix2dos]
            -- [[<argument1>] ... [<argumentN>]]

To run your python script, you can enter the following - stdout and stderr are returned to the host machine by this command

VBoxManage guestcontrol "Name of Virtual Machine Goes Here" exec --image /path/to/my/script --username UserNameGoesHere --password PasswordGoesHere --wait-exit --wait-stdout --wait-stderr

In my case the test script was

#!/usr/bin/python
print "hello"

You can find information about this by starting the VirtualBox program, and selecting Help from the menu, and the specific section you are looking for is 8.31. VBoxManage guestcontrol

Charles Green
  • 21,339
  • The information you gave me here (i guess you edited the answer again) is enough for me. I will build my solution around the information you gave me. Thank you very much for the help. –  Jul 03 '14 at 13:05
  • 1
    Di nada - I learn a little every time I try to figure something out like this. A tip - if you receive an error when you try to do this, it means that the VBox Guest additions are not fully installed. Several people have mentioned that in Linux, for some reason, they needed to do the installation twice (I needed to!) – Charles Green Jul 03 '14 at 13:08
  • It's not working with the current version of VBoxManage since the syntax has changed. But the current parameter --exe says "Provided path is not executable"... Any idea how can we overcome this error? – Arockia Nov 30 '17 at 01:04
  • @arockia I have given up on vmware and switched to KVM/QEMU... – Charles Green Nov 30 '17 at 01:13
1

The easiest way to launch an app in guest is to send a keyboard key press to guest from host. In the guest the app is setuped to launch on a key press (Using settings -> keyboard shortcuts or ccsm or any other ways). From a terminal or from a script we send the key press to guest, on listening that guest OS launch the program/app.

To send a key press use the VBoxManage's option keyboardputscancode
For example
VBoxManage controlvm [name] keyboardputscancode 1d 38 e0 53 will send Ctrl + Alt + Delete and VBoxManage controlvm [name] keyboardputscancode 38 24 will send Alt + J.

The advantage of this method is you don't need to install any software, even guest additions. You don't need to setup any network, ssh, passwords etc..
Scan codes for a key can be found here.

totti
  • 6,818
  • 4
  • 39
  • 48