Skip to content
Permalink
Browse files

[processing][GRASS] Fix exceptions on Python < 3.6

Fixes #21173

(cherry picked from commit 5fca18c)
  • Loading branch information
nyalldawson committed Mar 4, 2019
1 parent b96f281 commit 3121761171fde67494e47c75b6baf1e0b8f9e4dc
Showing with 11 additions and 4 deletions.
  1. +11 −4 python/plugins/processing/algs/grass7/Grass7Utils.py
@@ -30,6 +30,7 @@
import shlex
import subprocess
import os
import sys

from qgis.core import (Qgis,
QgsApplication,
@@ -356,10 +357,14 @@ def executeGrass(commands, feedback, outputCommands=None):
# QgsMessageLog.logMessage('exec: {}'.format(command), 'DEBUG', Qgis.Info)

# For MS-Windows, we need to hide the console window.
kw = {}
if isWindows():
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
kw['startupinfo'] = si
if sys.version_info >= (3, 6):
kw['encoding'] = "cp{}".format(Grass7Utils.getWindowsCodePage())

with subprocess.Popen(
command,
@@ -369,8 +374,7 @@ def executeGrass(commands, feedback, outputCommands=None):
stderr=subprocess.STDOUT,
universal_newlines=True,
env=grassenv,
encoding="cp{}".format(Grass7Utils.getWindowsCodePage()) if isWindows() else None,
startupinfo=si if isWindows() else None
**kw
) as proc:
for line in iter(proc.stdout.readline, ''):
if 'GRASS_INFO_PERCENT' in line:
@@ -401,10 +405,14 @@ def executeGrass(commands, feedback, outputCommands=None):
if not grassOutDone and outputCommands:
command, grassenv = Grass7Utils.prepareGrassExecution(outputCommands)
# For MS-Windows, we need to hide the console window.
kw = {}
if isWindows():
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
kw['startupinfo'] = si
if sys.version_info >= (3, 6):
kw['encoding'] = "cp{}".format(Grass7Utils.getWindowsCodePage())
with subprocess.Popen(
command,
shell=False,
@@ -413,8 +421,7 @@ def executeGrass(commands, feedback, outputCommands=None):
stderr=subprocess.STDOUT,
universal_newlines=True,
env=grassenv,
encoding="cp{}".format(Grass7Utils.getWindowsCodePage()) if isWindows() else None,
startupinfo=si if isWindows() else None
**kw
) as proc:
for line in iter(proc.stdout.readline, ''):
if 'GRASS_INFO_PERCENT' in line:

0 comments on commit 3121761

Please sign in to comment.
You can’t perform that action at this time.