Capture any system call errors

Revised from previous commit which only captured the result.