use communicate instead of wait in subprocess