Error: Command failed: C:\windows\system32\cmd.exe /s /c "E:\programfiles\androidSDK\platfor...

問題

appium等自動化環境都安裝配置號後,遇到以下問題:node

Error: Command failed: C:\windows\system32\cmd.exe /s /c "E:\programfiles\androidSDK\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'""android

解決方案

網上找到了解決方法,點擊這裏 也可查看本篇shell

  • 他講的內容彷佛有點重複,第一步改好的,在最後一步註釋掉了。

具體步驟以下:windows

1.找到adb.js文件,路徑爲appium的安裝路徑下:node_modules\appium\node_modules\appium-adb\lib 2.找到以下代碼:app

ADB.prototype.shell = function (cmd, cb) {
  if (cmd.indexOf('"') === -1) {
    cmd = '"' + cmd + '"';
  }
  var execCmd = 'shell ' + cmd;
  this.exec(execCmd, cb);
};

修改:var execCmd = 'shell ' + cmd;var execCmd = 'shell ' + cmd + '| grep ' + grep;
3.找到以下代碼:ui

ADB.prototype.getPIDsByName = function (name, cb) {
  logger.debug("Getting all processes with '" + name + "'");
  this.shell("ps '" + name + "'", function (err, stdout) {
    if (err) return cb(err);
    stdout = stdout.trim();
    var procs = [];
    var outlines = stdout.split("\n");
	outlines.shift();
    _.each(outlines, function (outline) {
      if (outline.indexOf(name) !== -1) {
        procs.push(outline);
      }
    });
    if (procs.length < 1) {
      logger.debug("No matching processes found");
      return cb(null, []);
    }
    var pids = [];
    _.each(procs, function (proc) {
      var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
      if (match) {
        pids.push(parseInt(match[1], 10));
      }
    });
    if (pids.length !== procs.length) {
      var msg = "Could not extract PIDs from ps output. PIDS: " +
                JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
      return cb(new Error(msg));
    }
    cb(null, pids);
  });
};

修改成:this

ADB.prototype.getPIDsByName = function (name, cb) {
  logger.debug("Getting all processes with '" + name + "'");
  this.shell_grep("ps", name, function (err, stdout) {
    if (err) {
      logger.debug("No matching processes found");
      return cb(null, []);
    }
    var pids = [];
    _.each(procs, function (proc) {
    var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
    if (match) {
    pids.push(parseInt(match[1], 10));
    }
    });
    if (pids.length !== procs.length) {
      var msg = "Could not extract PIDs from ps output. PIDS: " +
      JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
      return cb(new Error(msg));
    }
    cb(null, pids);
  });
};
相關文章
相關標籤/搜索