Skip to content

Instantly share code, notes, and snippets.

@jsdario
Created August 9, 2018 08:22
Show Gist options
  • Save jsdario/8c695e803fc0945ea5848e22b924b852 to your computer and use it in GitHub Desktop.
Save jsdario/8c695e803fc0945ea5848e22b924b852 to your computer and use it in GitHub Desktop.
Run adb commands in multiple devices at the same time, useful for React Native commands and other mobile developers
const {exec} = require('child_process')
exec('adb devices', (err, stdout, stderr) => {
if (err) {
console.error(err)
return
}
if (stderr) {
console.warn(stderr)
}
const [, ...devices] = stdout
.split('\n')
.filter(Boolean)
.map(str => str.split('\t')[0])
const args = process.argv.slice(2).join(' ')
devices.forEach(device => {
// eslint-disable-next-line
console.log(`adb -s ${device} ${args}`)
// eslint-disable-next-line
exec(`adb -s ${device} ${args}`, (err, stdout, stderr) => {
if (err) {
console.error(err)
return
}
if (stderr) {
console.warn(stderr)
}
// eslint-disable-next-line no-console
console.log(stdout)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment