Validate cmd

This is a continuation of https://github.com/puppetlabs/puppetlabs-stdlib/pull/113, with changes to better manage tempfiles as @jeffmccune recommended.