Use Popen .communicate() instead of .stdin.write() to avoid deadlocks.

Writing to Popen.stdin can cause a deadlock if the passed-in data is larger
than the OS's buffer. The communicate() method avoids this problem, and it
makes the code a bit shorter, too.

Testing done:
* Ran unit tests.
* Smoke tested a few diffs.

Fixes bug 2247.

Reviewed at https://reviews.reviewboard.org/r/5393/