Running an external algorithm or command
There are often a bunch of legacy programs or scripts for which there are no resources to port them into another language or framework. Thanks to Python and PyQGIS, it's simple to integrate your existing programs into QGIS.
Running a simple command
We can run an external command in different ways, but we will explore how to do it with the Processing Toolbox that supports the progress bar, which is often useful to log algorithm steps.
To execute an external command, we will follow these steps:
- Create a Processing Toolbox script called
runping
. - Code the script.
- Test the script.
Step one is similar to that described in the Creating a test Processing Toolbox script section.
The code of the script is in the following code snippet:
import subprocess import time proc = subprocess.Popen( ["ping", "-c", "10", "localhost"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) counter ...