I run a command from the host machine on the guest machine (both Ubuntu) as
VBoxManage guestcontrol Ubuntu1 run --exe "script.sh" --username xx --password xx --wait-stdout
where the shell script on the guest machine is as
#!/bin/bash
echo $1
How can I pass the argument 1 while executing the shell script?
I assumed it should work as
run --exe "script.sh arg1"
but it does not.
Best Answer
SSH
We can run an application on a virtual guest with an SSH session from the host to this machine. However this requires that networking was enabled, and that openssh-server was installed an runs on the guest machine.
VBoxManage guestcontrol
As an alternative we can use built-in features of Virtual Box to execute a program on a running guest VM. This can be done with
VBoxManage guestcontrol
.The example line below will just run
ls
on the virtual machine's root:Running a graphical application on the guest requires us to define the DISPLAY environment variable to the guest with the option
--putenv
. Next example will run and open gedit on the guest:We can also pass options to open a program. Next example will open a file
vmtest
in the guest gedit:Options and arguments are separated from the command with
--
as can best be seen in below example of a script from the host.Example host script
Below script will play an
example.ogg
file usingpaplay
in a guest machine when run on the host. Replace the variables with appropriate values.