Wrap piping command inside a begin/rescue to catch invalid commands

Fixes #341