Changed 'commands' to 'subprocess' and added handling for stderr and stdout