p.communicate() can be brought out of this if/else block- the default argument for communicate() is already None, so passing stdin will have no effect in that case