Skip to content
Permalink
Browse files

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

Fixes #21173
  • Loading branch information
nyalldawson committed Mar 5, 2019
1 parent 33af405 commit 5fca18c4ae2c4df833fa0b687bd7e1d15ff39499
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,
@@ -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,
@@ -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:
@@ -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,
@@ -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:

0 comments on commit 5fca18c

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