Small style point here.  When there's only one parenthesized capture group in the regex, indices 0 and 1 return the same thing when you apply the array index operator to the `match()` results, so you could write

    sid = sid_regex.match(result.stdout).first

which I think is marginally more idiomatic Ruby.