Yes, if you are using `cmd` you can get exitcode by $?.exitstatus
Or you can use resurl = system(cmd) to get success (true/false)
Or you can use Puppet's cmd system to get both error processing and debug output.

All ways are correct but third is better.