Running an external algorithm or command
Often there are 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 = 0 for line in iter(proc.stdout.readline, '')...