Created
August 9, 2018 08:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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