I am using a shell script to build apk. In that script i am executing several commands one by one. Now the problem is how i know that my previous command successfully executed or not. Because in my script command executed in serial, does not matter first one is executed correctly or not. How to resolve this problem ?
If you’re saying you have something like this:
#!/bin/bash ./gradlew assembleDebug ./gradlew assembleDemoDebug
Then, you can check the value of the shell variable
$? after each call. It should be
0 if successful, otherwise non-zero.
I tried your last command but its throwing an error
Task ‘assembleDemoDebug’ not found in root project.
You’re asking about shell scripting implementation in a Gradle forum. I didn’t give you any commands to use. I made up an example to at least have some Gradle relevance and verify that’s what you’re doing, but you should actually be using whatever is in your real script.
Either way though, the
$? variable is still what you want to be checking for a zero or non-zero value, if you want to know if the previous command was successful.
Thanks for the reply.
But i think you did not get my point. My question is how to know our command executed successfully?
i have several command like ./gradlew clean, ./gradlew assembleDebug etc
Every command returns BUILD SUCCESSFUL when successfully executed and BUILD FAILED when failed. So how i know which command failed or success.?
I’ve answered that particular question in each of my responses. If that’s not really what you’re wanting to know though, you probably need to provide a more detailed example of what you have and what it really needs to do.
That answer has been to check the value of
$?. In a shell script,
$? tells you specifically if your last command executed successfully. I have no idea what you’re intending to do differently, but here’s a contrived example with the two tasks you mentioned and some output:
#!/bin/bash ./gradlew clean if [ $? -ne 0 ]; then echo "Clean failed. Something is really wrong. Contact a system admin. We won't try to assemble the app." exit 1 fi ./gradlew assembleDebug if [ $? -ne 0 ]; then echo "Assemble failed. There might be a problem with the code being assembled." exit 1 fi