Executes shell commands and captures output securely, avoiding vulnerabilities of Ruby's backtick operator.