mirror of
https://github.com/taigrr/adb.git
synced 2026-04-02 02:58:42 -07:00
arbitrary exec example functional
This commit is contained in:
36
examples/shellExec/main.go
Normal file
36
examples/shellExec/main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/taigrr/adb"
|
||||
)
|
||||
|
||||
func main() {
|
||||
command := "ls"
|
||||
ctx := context.TODO()
|
||||
devs, err := adb.Devices(ctx)
|
||||
if err != nil {
|
||||
fmt.Printf("Error enumerating devices: %v\n", err)
|
||||
return
|
||||
}
|
||||
for _, dev := range devs {
|
||||
if !dev.IsAuthorized {
|
||||
fmt.Printf("Dev `%s` is not authorized, authorize it to continue.\n", dev.SerialNo)
|
||||
continue
|
||||
}
|
||||
stdout, stderr, errcode, err := dev.Shell(ctx, command)
|
||||
_ = stderr
|
||||
_ = errcode
|
||||
switch {
|
||||
case err == nil:
|
||||
case errors.Is(err, adb.ErrUnspecified):
|
||||
default:
|
||||
fmt.Printf("Error running shell command `%s` on dev `%s`: %v\n", command, dev.SerialNo, err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("%s:\n\n%s\n", dev.SerialNo, stdout)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user