Add error checking to 'cmd' buffer as it may not be available (ie. in the case of exec).