Wait for exit

fixes #1365