Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing][GRASS] Fix exceptions on Python < 3.6
Fixes #21173

(cherry picked from commit 5fca18c)
  • Loading branch information
nyalldawson committed Mar 7, 2019
1 parent b96f281 commit 3121761
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -30,6 +30,7 @@
import shlex
import subprocess
import os
import sys

from qgis.core import (Qgis,
QgsApplication,
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 3121761

Please sign in to comment.