Is it possible to execute/call an external application in Windows or a batch file (bat) using the QGIS Graphic Modeller? I am using QGIS version 3.28.7


1 Answer 1


You could create a processing script that calls the bat/sh/exe using the subprocess python module.

enter image description here

E.g. a simple processing script that takes one input, a CSV file, passes it to an external batch file and captures the output of the batch file (the number of lines in the input CSV) and returns that:

from qgis.processing import alg
import subprocess

@alg(name="shellscript", label=alg.tr("shellscript"), group='examplescripts', group_label='Example scripts')
@alg.input(type=alg.FILE, name="CSV_INPUT", label="CSV File")
@alg.output(type=alg.NUMBER, name='OUTPUTFEATURES', label='Number of features processed')
def shellscript(instance, parameters, context, feedback, inputs):
    """Description goes here. (Don't delete this! Removing this doc string will cause errors.)"""

    output = subprocess.check_output(["/path/to/test.bat", parameters["CSV_INPUT"]])

    return {'OUTPUTFEATURES': int(output)}

This processing script can then be added to a model:

enter image description here

  • Thank you @user2856 exactly what I needed. Never tried it but time to learn something new.
    – GforGIS
    Commented Jun 9, 2023 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.