Run commands on an Ubuntu guest in VirtualBox VM from Windows host
Here is the help from the vboxmanage
command:
guestcontrol <uuid|vmname>
exec[ute]
--image <path to program> --username <name>
[--passwordfile <file> | --password <password>]
[--domain <domain>] [--verbose] [--timeout <msec>]
[--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"]
[--wait-exit] [--wait-stdout] [--wait-stderr]
[--dos2unix] [--unix2dos]
[-- [<argument1>] ... [<argumentN>]]
So the full command should be:
C:\Program Files\Oracle\VirtualBox\VBoxManage guestcontrol "Ubuntu" execute --username (myname) --password (mypassword) --verbose --wait-exit --wait-stdout --image "/usr/local/bin/oof2" -- --text
Note the extra --
. Everything after that will be passed as arguments to the process.
Setting Up SSH
- Install PuTTY on the host machine. (Direct link to installer)
- Open a terminal in the VM and type
ip -4 addr
. Look for your IP address, it'll be next to the word "inet" under the "eth0" section (probably going to be 10.0.2.XXX) - From the VM window, open the "Device" menu, and select "Network"->"Network Settings". From there select "Port Forwarding"
- Add a rule, Host Port = 2222, Guest IP = , Guest Port = 22. Click OK on all dialogs.
- Run putty, use
localhost
as the hostname, and2222
as the port. Click "Open"
If that works and you get a terminal, you can now use this command to run your application:
C:\Program Files (x86)\PuTTY\plink.exe -P 2222 -pw mypassword myname@localhost "/usr/local/bin/oof2" --text
Related videos on Youtube
![Hogy88](https://i.stack.imgur.com/fk9Ro.jpg?s=256&g=1)
Hogy88
Updated on September 18, 2022Comments
-
Hogy88 almost 2 years
I am working on some coding, and I have an idea that should work but I have no clue how to make it work. I am using Wolfram Mathematica on my Windows host machine to run some code, but I have to export a file to a Linux-based program that I run in an Ubuntu Virtualbox VM. As of now, when the file is exported, I have to go over and click it to make it run.
While it's not too much work, I'd like to have it automated so that Mathematica can call my other program and I don't have to click anything. I've done my best to look around online for help, but honestly it's mostly over my head (I'm a civil engineer, not really computer savvy).
Here's what I've got so far:
C:\Program Files\Oracle\VirtualBox\VBoxManage guestcontrol "Ubuntu" execute --username (myname) --password (mypassword) --verbose --wait-exit --wait-stdout --image "/home/(myname)/Desktop/oof2-2.1.11/oof2"
It tells me
VERR_ACCESS_DENIED
and closes the guest session.When I run my program in Ubuntu, all I have to do is type
oof2
in the terminal window and it starts up, but how do I get it to do this via the command line? I've read through the guest control manual for VirtualBox and I didn't see anything that I can understand that directly applies. Any help is appreciated.As a final note, I can run the examples given in the guest control manual and they work fine.
-
heavyd over 9 yearsIf you login to the Ubuntu machine from VirtualBox can you execute the app using the full path
/home/(myname)/Desktop/oof2-2.1.11/oof2
? -
Hogy88 over 9 yearsWell, I actually cannot. It initially said "access denied", so I did sudo ..., and it said "command not found". How do I find out which path the terminal is using? Again, I just type "oof2" and it pops up.
-
heavyd over 9 yearstry
which oof2
-
heavyd over 9 years
oof2 --help
oroof2 -h
see if there is an option to pass it a script. But if you're trying to start a GUI application, you might have a hard time because VirtualBox is starting a new session for your user that wouldn't be associated with the current desktop. -
Hogy88 over 9 yearsI can type '/usr/local/bin/oof2 --text' into the Ubuntu terminal and it runs the text version, from which I can load a script (still in the terminal). I'm not sure how to make this work in the command line, though. I tried "--image '/usr/local/bin/oof2 --text'" and that didn't work. By the way, your help is appreciated more than you know. I've been working on this for several days now with little headway until the last hour.
-
heavyd over 9 yearsTake the
--text
out of the quotes:--image '/usr/local/bin/oof2' --text
-
Hogy88 over 9 yearsReturns: Process started (next line) <-[1;24r<-[0;10m<-[4l<-[?7h<-[24;1HProcess terminated (end) where <- is an arrow. If I type in the script I want it to load after the --text, it says "error: Unknown option: --text"
-
-
Hogy88 over 9 yearsDo you have any knowledge about Python curses? It's giving me '_curses.error: endwin() returned ERR Process terminated'
-
heavyd over 9 yearsI don't, but I'd assume it has to do with running it this way. Have you tried running it over SSH instead?
-
Hogy88 over 9 yearsI have not, and I don't know what that is yet (sorry...if you imaging Homer Simpson trying to code, I'm pretty close)
-
heavyd over 9 yearsNo problem, it's a way of connecting over the network instead of through virtual box. Is the VM connected to the network? If so which network type is selected in VB (NAT, bridged, etc.)?
-
Hogy88 over 9 yearsIt's a NAT connection.
-
heavyd over 9 years@Hogy88, I've update my answer with instructions for SSH.
-
Hogy88 over 9 yearsFigured it out!!!! I'm so excited, it's unreal. The full code is C:\Program Files\Oracle\VirtualBox\VBoxManage guestcontrol "Ubuntu" execute --username (myname) --password (mypassword) --verbose --wait-exit --wait-stdout --image "/usr/local/bin/oof2" -- --batch --script="(script location)" This is great, my research will be worlds faster now that I can do this. Thank you so much for your help!!! Is there a way I can recommend you, that sort of thing? Not sure how this site works yet.