Changed program invocation to use popen, fixed an off-by-one