Use communicate instead of wait

To fix the script from hanging.