Question:
Imagine a DOS style .cmd file which is used to launch interdependent windowed applications in the right order.
Example:
1) Launch a server application by calling an exe with parameters.
2) Wait for the server to become initialized (or a fixed amount of time).
3) Launch client application by calling an exe with parameters.
What is the simplest way of accomplishing this kind of batch job in PowerShell?
Answer:
Remember that PowerShell can access .Net objects. The Start-Sleep as suggested by Blair Conrad can be replaced by a call to WaitForInputIdle of the server process so you know when the server is ready before starting the client.
1 2 3 |
$sp = get-process server-application $sp.WaitForInputIdle() |
You could also use Process.Start to start the process and have it return the exact Process. Then you don’t need the get-process.
1 2 3 4 |
$sp = [diagnostics.process]::start("server-application", "params") $sp.WaitForInputIdle() $cp = [diagnostics.process]::start("client-application", "params") |