0

i have a simple batch script for GRADLE android as below

@ECHO ON
set DIR=path
set APP=%DIR%\app1
cd %APP%
./gradlew assembleDebug

next i want to check when Gradlew build is done, i can continue next command something like

if(./gradlew assembleDebug) then echo "pass"
else echo "failed"

but i don't know how to implement in batch script

anyone know please tell me how to implement

thanks

oguz ismail
  • 1
  • 16
  • 47
  • 69
adragon
  • 11
  • 1
  • 6
  • 1
    I suppose this should work: `if errorlevel 1 (echo failed) else echo pass` – Aacini Sep 24 '21 at 05:00
  • The first line should be `@echo off`. The second and third line can be removed and so the second line is `cd /D "path\app1"` whereby if `path` should be the path of the directory containing the batch file, it is possible to use `cd /D "%~dp0app1"` to change the current directory to the subdirectory `app1` of the batch file directory. The third command line depends on what `gradlew` is. There should be used `.\gradlew.exe assembleDebug` if the file `gradlew` has the file extension `.exe` which should be the case according [gradlew info](https://stackoverflow.com/tags/gradlew/info). – Mofi Sep 25 '21 at 21:18
  • The Windows command processor `cmd.exe` processing a batch file waits for self-termination of a started executable on running it from within a batch file independent on being a Windows console or Windows GUI application. A Windows console application __usually__ exits with value `0` on success and a value __greater__ `0` if there an error occurred. But there are exceptions like [ROBOCOPY](https://ss64.com/nt/robocopy-exit.html). So please read the documentation respectively user guide of [The Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). – Mofi Sep 25 '21 at 21:24
  • __Wait!__ It looks like the Gradle Wrapper is not an executable with file extension `.exe`, but a batch file with file extension `.bat`, i.e. the file name with extension is `gradlew.bat`. That makes a big difference as in this case must be used `call .\gradlew.bat assembleDebug` as explained in [this answer](https://stackoverflow.com/a/24725044/3074564). Otherwise the Windows command processor `cmd.exe` __continues__ the current batch file processing on `gradlew.bat` without ever coming back to your batch file for processing and executing the next command line. – Mofi Sep 25 '21 at 21:29
  • The processing of a __called__ batch file can end also with exit code `0` for success and a different (greater) value than `0` for indicating an error condition. The exit code of a started executable or a called batch file is assigned by `cmd.exe` to its internal variable `ERRORLEVEL` and the command __IF__ can be used to continue further batch file processing depending on the value assigned currently to `ERRORLEVEL`. The help of __IF__ output on running `if /?` in a [command prompt](https://www.howtogeek.com/235101/) explains on first page how to evaluate `ERRORLEVEL` with correct syntax. – Mofi Sep 25 '21 at 21:43
  • So the fourth command line can be `if errorlevel 1 (echo failed) else echo pass` as suggested by __Aacini__. For completeness read first [single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564). Then you should have the knowledge that `call .\gradlew.bat assembleDebug && echo pass|| echo failed` could be also used to output a line with `pass` on success (exit code is `0`) or with `failed` on failure (exit code is not equal `0`). – Mofi Sep 25 '21 at 21:43

0 Answers0