Move reading of input from stdin to a common helper

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>