1

So, I'm making a little batch script to be able to automate the whole process of flashing new roms for my Galaxy S6. Since its screen is broke, I have to do everithing manually from the adb shell, and since i'm having so many troubles with all the roms, I decided to make a little script to make my life easier.

This is what I got so far:

@echo off
setlocal enabledelayedexpansion

REM Factory settings

echo Formatting to Factory Defaults
adb reboot recovery
adb wait-for-usb-recovery
adb shell twrp wipe cache
adb shell twrp wipe dalvik
adb shell twrp wipe data
adb shell umount /sdcard
adb shell umount /sdcard
adb shell umount /data
adb shell umount /data
adb shell mke2fs -t ext4 /dev/block/platform/15570000.ufs/by-name/USERDATA
adb shell reboot recovery
adb wait-for-usb-recovery

REM Rom Flashing Section

set argCount=0
for %%x in (%*) do (
    set /A argCount+=1
    set "argVec[!argCount!]=%%~x"
)

echo Wiping /system
adb shell twrp wipe /system

for /L %%i in (1,1,%argCount%) do (
    adb wait-for-usb-recovery
    echo Flashing "!argVec[%%i]!"
    adb shell twrp sideload
    adb wait-for-usb-sideload
    adb sideload "!argVec[%%i]!"
    echo "!argVec[%%i]!" flashed
    echo.
)

REM Debug enable

adb wait-for-usb-recovery
echo Enabling USB Debugging
adb shell mount system
adb shell "echo '' >> /system/system/build.prop"
adb shell "echo '# Enable ADB' >> /system/system/build.prop"
adb shell "echo 'persist.service.adb.enable=1' >> /system/system/build.prop"
adb shell "echo 'persist.service.debuggable=1' >> /system/system/build.prop"
adb shell "echo 'persist.sys.usb.config=mtp,adb' >> /system/system/build.prop"

adb push C:\Users\ffpp2\.android\adbkey.pub /data/misc/adb/adb_keys

REM Booting system

echo Rebooting into system...
adb shell reboot
echo waiting for phone to boot up
adb wait-for-usb-device
echo Launch scrcpy
"D:\Users\ffpp2\Documents\Celus\zeroflte\scrcpy-win64-v1.25\scrcpy.exe"

Now, I want to be able to evaluate every adb shell ... return code, so if anything happens mid way I can stop execution and I can get to fix what didn't work.

I havent been able to find anything regarding if adb shell forwards error codes back to the windows command prompt. Take a look at this:

D:\Users\ffpp2\Documents\Celus\zeroflte>adb shell mount /system
mount: mounting /dev/block/sda15 on /system failed: Device or resource busy

D:\Users\ffpp2\Documents\Celus\zeroflte>echo %errorlevel%
0

D:\Users\ffpp2\Documents\Celus\zeroflte>adb shell
~ # mount /system
mount: mounting /dev/block/sda15 on /system failed: Device or resource busy
~ # echo $?
255
~ # exit

D:\Users\ffpp2\Documents\Celus\zeroflte>adb shell cat asd
cat: can't open 'asd': No such file or directory

D:\Users\ffpp2\Documents\Celus\zeroflte>echo %errorlevel%
0

D:\Users\ffpp2\Documents\Celus\zeroflte>adb shell
~ # cat asd
cat: can't open 'asd': No such file or directory
~ # echo $?
1
~ #

As you can see, no error code was returned. And, in theory, it should be returned, since I didnt used the -x argument:

Android Debug Bridge version 1.0.41
Version 34.0.0-9570255
Installed as C:\Program Files (x86)\ADB and Fastboot++\adb.exe
...
shell:
 shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
     run remote shell command (interactive shell if no command given)
     -e: choose escape character, or "none"; default '~'
     -n: don't read from stdin
     -T: disable pty allocation
     -t: allocate a pty if on a tty (-tt: force pty allocation)
     -x: disable remote exit codes and stdout/stderr separation
 emu COMMAND              run emulator console command
...

Has TWRP anything to do with this?

3
  • I am afraid that is windows issue
    – alecxs
    Feb 15, 2023 at 7:47
  • 1
    adb shell doesn't seem to return the exit code no matter which host OS you use. The only way to get it seem to be a workaround like the one described here: stackoverflow.com/questions/17480028/…
    – Robert
    Feb 15, 2023 at 8:14
  • works for me on Xubuntu 20.04 LTS
    – alecxs
    Feb 16, 2023 at 10:09

0

You must log in to answer this question.

Browse other questions tagged .