Skip to content

Instantly share code, notes, and snippets.

@adamfortuno
Created December 14, 2018 21:36
Show Gist options
  • Save adamfortuno/ff79c2d26ab6675242ef933e3505ed4d to your computer and use it in GitHub Desktop.
Save adamfortuno/ff79c2d26ab6675242ef933e3505ed4d to your computer and use it in GitHub Desktop.
Launch a Process, Create an Event Waiting for it to Complete, and Do Something When the Event Fires
/******************************************************************************
Situation...
There is a DOS batch script named foo.bat in C:\temp\foo.bat. We want
******************************************************************************/
$things-todo-when-batchfile-completes = {
new-item 'c:\temp\thinger-done.txt'
Get-EventSubscriber | Unregister-Event
}
$file_run = Start-Process -FilePath ".\thing.bat" -PassThru
$job = register-objectevent -InputObject $file_run `
-eventname exited `
-SourceIdentifier test `
-Action $event_response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment