0

i have a script for adb batch and i'm having difficulty in checking version with batch command let this script:

@echo off
set sdkversioncheck=adb shell getprop ro.build.version.sdk
set ver=28
if %sdkversioncheck% gtr %ver% (@echo "Greater Version") else (@echo "Lower Version")
@pause >NUL

i want this one to check the android version if device is plugged in and adb commands are working and whenever i try to run above command then i get this in response: shell was unexpected at this time.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Vicky Malhotra
  • 340
  • 1
  • 4
  • 13
  • 1
    The problem is with your understanding of how the `cmd` shell works, as opposed to other shells. The result of `%sdkversioncheck%` is the string `adb shell getprop ro.build.version.sdk`, not the value returned from the command `adb shell getprop ro.build.version.sdk`. If you want to get the result of a command as the value assigned to a variable, and as that has been asked and answered many times on StackOverflow, I'd suggest you put that into the search box at the top of this page. It will help with your search, if you first read [this](https://stackoverflow.com/help/searching) advice. – Compo Nov 27 '20 at 13:18
  • First two rules of debugging a batch file is to not use `echo off` and to run the script from an already opened cmd shell. If you would have done that you would have seen how the code was actually executing. – Squashman Nov 27 '20 at 16:50
  • @Compo i try to search before asking any question and also i tried it like this but it doesn't works...`if "adb shell getprop ro.build.version.sdk" gtr 25 (@echo "Greater Version") else (@echo "Lower Version")` any suggestion? – Vicky Malhotra Nov 27 '20 at 18:22
  • @Squashman above script is a demo script and for you info i turn off the echo option when debugging/checking the script function with double colon:: and i execute it with `cmd /k myfile.bat command to get clean info` but still don't know why it's not working... – Vicky Malhotra Nov 27 '20 at 18:24
  • 1
    I didn't say you hadn't searched, obviously before I told you what your issue was, it is unlikely you'd have searched for it! What you needed to search for was something along the lines of [\[batch-file\] result command variable](https://stackoverflow.com/search?q=%5Bbatch-file%5D+result+command+variable). You should have noticed from the answers in the returned results that you needed to use a `for /f` loop, to run the command and capture its result in a retrievable format. What you've now shown is checking if the string `adb shell getprop ro.build.version.sdk` is greater than an integer! – Compo Nov 27 '20 at 19:28

0 Answers0