Single preexec_fn with error handling, like subprocess.Popen

As discussed over on pexpect/pexpect#81, this replaces the `before_exec` iterable with a single `preexec_fn` function, which works like `preexec_fn` in subprocess.Popen. Errors from preexec_fn are crudely sent through a pipe to the parent process; again, this is like what subprocess does.