1

I want make batch file using adb and prompt

For instance: I need Huawei P40 info from batch:

P40
Model : ANA-AN00
OS : 12
Build Type : User
Build Number : P40Blahblahblah
sdk version : blahblah

like this.
I can saw on adb (adb shell getprop ro.blahblah) but I can't make to batch file.
I weak to CLI... pls help me

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
강승오
  • 13
  • 2

1 Answers1

0

You need to grep the values returns by adb shell getprop as in here.

For each value, you can set it in a variable, and then print it with the format you want.

Example:

model=$(adb shell getprop | grep model | cut -d ":" -f 2)
# Or, simpler
model=$(adb shell getprop ro.product.model)
echo "model='${model}'"

The OP 강승오 adds in the comments:

I got app ver from 'adb shell dumpsys package mypackage | grep"'versionName="' and I checked I want to display App ver : 1.2.345 but, displayed on result App ver : versionName=1.2.345.
how to solve this?
I tried set str command set str:%str:versionName=:% after then nothing displayed on app ver app ver : (blank).

If you have set that result to a variable, you can replace the part you don't want:

res=$(adb shell dumpsys package mypackage | grep"'versionName=")
res=${res/versionName=/}
echo "res='${res}'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So nice, but I solved. Thx VonC! I will use temp variable But your Answer is so nice help to me! – 강승오 Aug 14 '22 at 20:10
  • @강승오 Great, well done! – VonC Aug 14 '22 at 20:11
  • Um... Mr.VonC I have a question Can you answer it? I wanna check app ver without " | grep" command – 강승오 Aug 14 '22 at 20:39
  • @강승오 Try `adb shell getprop ro.build.version.sdk`. It depends on what "version" you want though. – VonC Aug 14 '22 at 20:49
  • Um... I mean. I need a specific app ver. Third Party App. for example chrome, firefox, WeChat etc – 강승오 Aug 14 '22 at 21:01
  • @강승오 Then you need to process `adb shell dumpsys package`, as explained in "[Get application version name using adb](https://stackoverflow.com/a/56313536/6309)" – VonC Aug 14 '22 at 21:04
  • OK I will try later. here is 6 AM lol Thx VonC! – 강승오 Aug 14 '22 at 21:16
  • @강승오 No problem. Have a good (late) night. – VonC Aug 14 '22 at 21:17
  • my batch console almost complete. but, I can't solve last problem. I got app ver from 'adb shell dumpsys package mypackage | grep"'versionName="' and I checked I want to display App ver : 1.2.345 but, displayed on result App ver : versionName=1.2.345 how to solve this? I tried set str command set str:%str:versionName=:% after then nothing displayed on app ver app ver : (blank) – 강승오 Aug 15 '22 at 14:46
  • @강승오 I have edited the answer to address your comment. – VonC Aug 15 '22 at 19:38
  • I tried, but if i add your command, my batch do not work. maybe I misunderstand. I'm using now `for /f %%C IN ('adb shell "dumpsys package org.mozilla.firefox | grep 'versionName='"') do set appver=%%C` and how to modify? Delete all command and change to your command? I'm confused sry. I'm so stupid – 강승오 Aug 16 '22 at 17:30