I developed a plugin on QGIS 2.18 in Python 2 (which works in a Linux environment) and I'm trying today to convert my code to Python3 so that I can use it on QGIS 3.18 and directly in a Windows environment.My plugin retrieves text information that the user fills in, and executes an .exe with subprocess.popen function and that's where I get stuck
import subprocess
proc = subprocess.Popen(['Traitement_2.exe', r"cd C:/Users/Utilisateur/Traitement"],stdout=subprocess.PIPE, stderr=subprocess.PIPE,encoding = "ISO-8859-1", shell=True, text=True) print(proc.stdout)
while True:
lecture = proc.stdout.readline()
print (lecture)
if 'FIN' in lecture:
print('Le Traitement est fini')
break
If I run this Python code in a Windows command prompt (by doing python test_py2.py), my program Traitement_2.exe runs and returns strings of characters (and only strings of characters) displayed in the console like this
**************************************
**************************************
TRAITEMENT 2 DE MESRI
CREATION DES FICHIERS :
- CARTE DU RSEAU HYDROGRAPHIQUE
- CARTE DES AIRES DRAINES PAR PIXEL
- CARTE DES DISTANCES VERSANT
- CARTE DES DISTANCE RSEAU
- CARTE DES CRTES
**************************************
**************************************
**************************************
IDENTIFICATION DES CRTES
**************************************
**************************************
CALCUL DES AIRES DRAINES
**************************************
**************************************
CALCUL DES DISTANCES DE PARCOURS
**************************************
**************************************
ECRITURE DES FICHIERS DE SORTIE
**************************************
FIN
But when I put this code in my plugin.py (QGIS plugin), nothing starts. I don't get an error either, I just have the impression that nothing happens. The read variable is of type but is empty.
Do you have a solution or something to think about?
What I have tried:
I developed a plugin on QGIS 2.18 in Python 2 (which works in a Linux environment) and I'm trying today to convert my code to Python3 so that I can use it on QGIS 3.18 and directly in a Windows environment.My plugin retrieves text information that the user fills in, and executes an .exe with subprocess.popen function and that's where I get stuck