Hi,
I have a VM that I have install DOS6.22 on to run a real old Business Application that is required. I am running the VM on a Windows 7 Host. At the moment I am performing the following steps to transfer Data to/from my new VM
1: Mount my VHD and copy files to it
2: Unmount my VHD
3: Start my VM in Virtual Box
4: Do the work that is required
5: Closed the VM
6: Mount the VHD and copy new files off
7: Unmount the VHD
I want to create a Simple BATCH Script that will manage all of the above for me. Mounting/Unmounting the VHD and copying files to/from the VHD is OK and working. My Problem is that when I issue the VBOXMANAGE.EXE command to start my VM, once the VM is starting it will give control back to the BAT File. Is there an option when starting the VM to not give control back to the BAT file until the opened VM is closed again, so when the BAT sees the User has closed the VM it will continue working.
Rgds
Chris
Controlling a VM with a BATCH Script
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Controlling a VM with a BATCH Script
The way to get a batch command to wait for an asynch process to terminate is to precede the normal console command with "start /wait", e.g. "start /wait VBoxManage ...etc".
One complication is that when VBoxManage starts a VM, that VM runs as a separate process from VBoxManage, so VBoxManage terminating doesn't mean that the VM has. Offhand I don't know of any way to get VBoxManage to wait for a VM to close. The only way I can think to do it is to have your own host tool that looks for the "VBoxSVC" process in the host task list.
One complication is that when VBoxManage starts a VM, that VM runs as a separate process from VBoxManage, so VBoxManage terminating doesn't mean that the VM has. Offhand I don't know of any way to get VBoxManage to wait for a VM to close. The only way I can think to do it is to have your own host tool that looks for the "VBoxSVC" process in the host task list.
-
noteirak
- Site Moderator
- Posts: 5231
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Controlling a VM with a BATCH Script
Directly call the front-end that you require, which won't return until the VM process is finished.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Controlling a VM with a BATCH Script
Sorry, but I'm pretty sure that isn't true. For example you can launch a VM from the GUI front end, then terminate the GUI app - the VM continues running. I don't see why the same would be untrue of VBoxManage.noteirak wrote:Directly call the front-end that you require, which won't return until the VM process is finished.
On Windows hosts the VBoxSVC process would be spawned (if not already running), and a VirtualBox.exe process for the VM itself. The front end (whatever it is) is then free to terminate.
-
noteirak
- Site Moderator
- Posts: 5231
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Controlling a VM with a BATCH Script
VBoxSVC will run whenever anything that requires the Virtualbox API is running. So if more than one VM is running, or that the Web-services is running, or anything of the like, it will NOT terminate.
So there is no way to wait for a specific VM using that way.
About the front-end, you are right about the Virtualbox one - it returns directly and spawn another process. On the other hand, vboxheadless does not return until the VM is Powered Off.
I guess it depends which front-end the OP wants to use now.
So there is no way to wait for a specific VM using that way.
About the front-end, you are right about the Virtualbox one - it returns directly and spawn another process. On the other hand, vboxheadless does not return until the VM is Powered Off.
I guess it depends which front-end the OP wants to use now.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
-
chrislynch8
- Posts: 2
- Joined: 13. Nov 2013, 18:54
Re: Controlling a VM with a BATCH Script
Hi all,
Thanks for the updates. I am directly calling the Front End I require with the following command
VBoxManage.exe "Dos" --type gui
This executes, starts the VM which is another process which is why the Script will continue. As far as it is concerned the VBoxMange.exe is finished.
So vboxmanage.exe starts the VBoxSVC.exe which spawns VirtualBox.exe
I'll need to think about this some more so.
Thanks for the updates. I am directly calling the Front End I require with the following command
VBoxManage.exe "Dos" --type gui
This executes, starts the VM which is another process which is why the Script will continue. As far as it is concerned the VBoxMange.exe is finished.
So vboxmanage.exe starts the VBoxSVC.exe which spawns VirtualBox.exe
I'll need to think about this some more so.
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Controlling a VM with a BATCH Script
Not quite. VBoxManage starts VirtualBox.exe, which is the VM. The VM relies on certain common services (e.g. virtual networking) which require VBoxSVC to be running, hence if it was not already running VBoxSVC will start. VBoxSVC terminates itself a few seconds after the last VM closes.chrislynch8 wrote:So vboxmanage.exe starts the VBoxSVC.exe which spawns VirtualBox.exe.