client.shell commands sequence
cabelloruizcarlos opened this issue · comments
Hi! I need to run a sequence of commands and I couldn't make this script work
var Promise = require('bluebird')
var adb = require('adbkit')
var client = adb.createClient()
client.listDevices()
.then(function(devices) {
return Promise.map(devices, function(device) {
var commands = ["am start -n com.android.settings/.DevelopmentSettings","input tap 100 1200"]
return client.shell(device.id, commands)
// Use the readAll() utility to read all the content without
// having to deal with the events. `output` will be a Buffer
// containing all the output.
.then(adb.util.readAll)
.then(function(output) {
console.log('Device Id = [%s]; Output = %s', device.id, output.toString().trim())
})
})
})
.then(function() {
console.log('Done.')
})
.catch(function(err) {
console.error('Something went wrong:', err.stack)
})
If I run only one command its working like a charm but when I added the array of commands the console is showing as an output this:
/system/bin/sh: am start -n com.android.settings/.DevelopmentSettings: not found
Any help on this?? Thanks in advance
And thanks for the library!!!!
When you pass .shell()
an array, it assumes that each item is a single argument that should be quoted. Either run the two commands separately or try .shell(..., 'am start -n com.android.settings/.DevelopmentSettings && input tap 100 1200')
.
It took me awhile to figure out how to use readAll()
with Promises so I'm positing it here to help others:
const stream = await adbClient.shell( config.udid, "ime list -s" )
const result = await adb.util.readAll( stream );
console.log( result.toString() ); // => com.sec.android.inputmethod/.SamsungKeypad