'How to run Gradle from a Python3 script

I want to run Gradle from a Python3 script. I can call Gradle from a terminal, but I can not figure out how to call it from a Python script.

example for call in terminal:

path gradle test --tests *SomeTest.someSpecificFeature*


Solution 1:[1]

I believe that's the correct way for running shell commands.

import subprocess
process = subprocess.Popen('path gradle test --tests *SomeTest.someSpecificFeature*', stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()

Solution 2:[2]

Try:

    import os
    os.system('path gradle test --tests *SomeTest.someSpecificFeature*')

You can invoke any shell command in such a manner.

See https://docs.python.org/3.6/library/os.html#os.system

Solution 3:[3]

This is how I run gradle in Python

import subprocess
res = subprocess.check_output('./gradlew -q getVersionName', shell=True)

To parse the result output

print(res.decode("utf-8"))

An example output will be

initialize  Gradle Environment .....
initialize  Gradle Environment completes...
3.0.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aviel Yosef
Solution 2 merrydeath
Solution 3 wMaN