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

问题

appium等自动化环境都安装配置号后,遇到如下问题:

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

解决方案

网上找到了解决方法,点击这里 也可查看本篇

  • 他讲的内容似乎有点重复,第一步改好的,在最后一步注释掉了。

具体步骤如下:

1.找到adb.js文件,路径为appium的安装路径下:node_modules\appium\node_modules\appium-adb\lib
2.找到如下代码:

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.找到如下代码:

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);
  });
};

修改为:

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);
  });
};
posted @ 2019-09-23 09:33  sky-walker  阅读(3678)  评论(0编辑  收藏  举报