tags:

views:

1592

answers:

1

I have a powershell 1.0 script to just open a bunch of applications. The first is a virtual machine and the others are development applications. I want the virtual machine to finish booting before the rest of the applications are opened.

In bash I could just say "cmd1 && cmd2".

This is what i've got...

C:\Applications\VirtualBox\vboxmanage startvm superdooper
&"C:\Applications\NetBeans 6.5\bin\netbeans.exe"
+6  A: 

Normally, for internal commands PowerShell does wait before starting the next command. One exception to this rule is external commands like an EXE. The first trick is to pipeline to Out-Null like so:

Notepad | Out-Null

PowerShell will wait until the Notepad process has been exited before continuing. That is nifty but kind of subtle to pick up from reading the code. You can also use Start-Process with the -Wait parameter:

Start-Process <path to exe> -NoNewWindow -Wait

If you are using the PowerShell Community Extensions version it is:

$proc = Start-Process <path to exe> -NoWindow
$proc.WaitForExit()

Another option in PowerShell 2.0 is to use a background job:

$job = Start-Job { invoke command here }
Wait-Job $job
Receive-Job $job
Keith Hill
My bad. Start-Process -Wait works great, but now I see it this is not what I was looking for...I'm actually seeking to wait until the vm to finishes booting. I imagine that's going to be tough. I suppose I'll have to find a new thread for that. Thanks but.
John Mee