//get command for running minicap in device func runMCinDeviceCmd(id, resolution string) (*exec.Cmd, error) { //defer portManager.freePort(id) var command *exec.Cmd var err error wh := strings.Split(resolution, "x") if len(wh) != 2 { return command, errors.New("resolution err") } w, err := strconv.Atoi(wh[0]) if err != nil { return command, errors.New("resolution err") } h, err := strconv.Atoi(wh[1]) if err != nil { return command, errors.New("resolution err") } sw := w * SCREEN_SIZE / h args := resolution + "@" + strconv.Itoa(sw) + "x" + strconv.Itoa(SCREEN_SIZE) + "/0" cmd := comm.CreateCmd("./minicap.sh " + args + " " + id) return cmd, nil }
//start logcat and send the content to websocket func startLogcat(id string) { devWS, ex := portManager.getDevWS(id) if !ex { log.Println("device websocket not exist") return } cmd := comm.CreateCmd(getADBPath() + " -s " + id + " logcat -v time") // Create stdout, stderr streams of type io.Reader stdout, err := cmd.StdoutPipe() if err != nil { log.Println(err) return } // Start command err = cmd.Start() if err != nil { log.Println(err) return } go func() { read := bufio.NewReader(stdout) for { content, _, err := read.ReadLine() if err != nil { log.Println(err) break } if len(content) > 0 { devWS.sendLog(content) } } }() }