Factor out subprocess code.