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 7032822 commit 773964b
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 @@ -370,10 +371,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 @@ -383,8 +388,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 @@ -415,10 +419,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 @@ -427,8 +435,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 773964b

Please sign in to comment.