Replace backticks with popen3 to support command failures