Extract readCmdStdout function