Wait for subprocess to complete