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..