mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:13:31 +02:00
run 'ps' first, then if it doesn't find the target process try 'ps -elf'
This commit is contained in:
@@ -39,28 +39,39 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||
shell: true
|
||||
}
|
||||
|
||||
return adb.shell(serial, 'ps -lef||ps')
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve) {
|
||||
var header = true
|
||||
var pids = []
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
if (header && chunk.toString().indexOf('bad pid') === -1) {
|
||||
header = false
|
||||
}
|
||||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin && users[cols[0]]) {
|
||||
pids.push(Number(cols[1]))
|
||||
}
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
resolve(pids)
|
||||
})
|
||||
})
|
||||
})
|
||||
var findProcess = function(out) {
|
||||
return new Promise(function(resolve) {
|
||||
var header = true
|
||||
var pids = []
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
if (header) {
|
||||
header = false
|
||||
}
|
||||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin && users[cols[0]]) {
|
||||
pids.push(Number(cols[1]))
|
||||
}
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
resolve(pids)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return adb.shell(serial, 'ps')
|
||||
.then(findProcess)
|
||||
.then(function(pids) {
|
||||
if (pids.length > 0) { // return pids if process can be found in the output of 'ps' command
|
||||
return Promise.resolve(pids)
|
||||
}
|
||||
else { // otherwise try to run 'ps -elf'
|
||||
return adb.shell(serial, 'ps -lef')
|
||||
.then(findProcess)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
|
||||
|
||||
Reference in New Issue
Block a user