Discussion:
Is there an equivalent of the DOS shell "start /wait" in PowerShel
(too old to reply)
Marco Shaw
2007-01-16 17:23:43 UTC
Permalink
Is there an equivalent of the DOS shell "start /wait", to allow a command,
especially a GUI exe, to finish before executing the next line in the
PowerShell.?
Specific example?
/\\/\\o\\/\\/ [MVP]
2007-01-16 19:12:46 UTC
Permalink
Now the powershell will hang after "$notepad.WaitForExit()" until you exit
notepad..
but not HAS too :


PoSH> $notepad = [System.Diagnostics.Process]::Start( "notepad.exe" )
PoSH> $notepad.WaitForExit


MemberType : Method
OverloadDefinitions : {System.Boolean WaitForExit(Int32 milliseconds),
System.Void WaitForExit()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Boolean WaitForExit(Int32 milliseconds),
System.Void WaitForExit()
Name : WaitForExit
IsInstance : True



PoSH> $notepad.WaitForExit(2000)
FalsePoSH> $notepad = [System.Diagnostics.Process]::Start( "notepad.exe" )
PoSH> $notepad.WaitForExit


MemberType : Method
OverloadDefinitions : {System.Boolean WaitForExit(Int32 milliseconds),
System.Void WaitForExit()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Boolean WaitForExit(Int32 milliseconds),
System.Void WaitForExit()
Name : WaitForExit
IsInstance : True



PoSH> $notepad.WaitForExit(2000)
False

more nice :

PoSH> if ( $notepad.WaitForExit(2000) ) {
"Notepad did quit in 2 seconds"} Else {
"Notepad did NOT quit in 2 seconds"}
Notepad did NOT quit in 2 seconds
PoSH> if ( $notepad.WaitForExit(10000) ) {
"Notepad did quit in 10 seconds"} Else {
"Notepad did NOT quit in 10 seconds"}
Notepad did quit in 10 seconds

more nice :

PoSH> $notepad = [System.Diagnostics.Process]::Start( "notepad.exe" )
PoSH> if ( $notepad.WaitForExit(10000) ) {
"running for $( (get-date) - $notepad.StartTime )"
}
running for 00:00:30.9150135

Greetings /\/\o\/\/
Is there an equivalent of the DOS shell "start /wait", to allow a
command,
especially a GUI exe, to finish before executing the next line in the
The easiest way to implement is to use a .NET class,
System.Diagnostics.Process to start a process and wait until the process
is
done.
The following illustrates how it can be done.(simpliest case without using
"System.Diagnostics.ProcessStartInfo" to pass process information)
# get a handle for the Notepad process to wait for
$notepad = [System.Diagnostics.Process]::Start( "notepad.exe" )
# wait indefinitely...
$notepad.WaitForExit()
Now the powershell will hang after "$notepad.WaitForExit()" until you exit
notepad..
Keith Hill [MVP]
2007-01-16 20:33:35 UTC
Permalink
Is there an equivalent of the DOS shell "start /wait", to allow a command,
especially a GUI exe, to finish before executing the next line in the
PowerShell.?
The PowerShell Community Extensions snapin has a Start-Process cmdlet that
is aliased to "start" and "saps". It has a parameter that allows you to
specify a wait (either indefinite or one that times out).

--
Keith

http://www.codeplex.com/powershellcx
/\\/\\o\\/\\/ [MVP]
2007-01-16 22:41:16 UTC
Permalink
old habbits ;-)
Post by Keith Hill [MVP]
Is there an equivalent of the DOS shell "start /wait", to allow a command,
especially a GUI exe, to finish before executing the next line in the
PowerShell.?
The PowerShell Community Extensions snapin has a Start-Process cmdlet that
is aliased to "start" and "saps". It has a parameter that allows you to
specify a wait (either indefinite or one that times out).
--
Keith
http://www.codeplex.com/powershellcx
$hay
2007-01-20 15:18:00 UTC
Permalink
take a look at "Managing Processes in PowerShell" from Bruce Payette
http://blogs.msdn.com/powershell/archive/2007/01/16/managing-processes-in-powershell.aspx
--
$hay
http://scriptolog.blogspot.com
Is there an equivalent of the DOS shell "start /wait", to allow a
command,
especially a GUI exe, to finish before executing the next line in the
The easiest way to implement is to use a .NET class,
System.Diagnostics.Process to start a process and wait until the process
is
done.
The following illustrates how it can be done.(simpliest case without using
"System.Diagnostics.ProcessStartInfo" to pass process information)
# get a handle for the Notepad process to wait for
$notepad = [System.Diagnostics.Process]::Start( "notepad.exe" )
# wait indefinitely...
$notepad.WaitForExit()
Now the powershell will hang after "$notepad.WaitForExit()" until you exit
notepad..
Loading...