Fixed hanging pexpect test on MacOS by using flush() instead of wait().