From 78384a6bce95b0e129e777800b968e422e95cf72 Mon Sep 17 00:00:00 2001 From: rblazek Date: Wed, 12 Apr 2006 13:05:59 +0000 Subject: [PATCH] emulate g.parser git-svn-id: http://svn.osgeo.org/qgis/trunk@5267 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/plugins/grass/qgsgrassmodule.cpp | 45 +++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/plugins/grass/qgsgrassmodule.cpp b/src/plugins/grass/qgsgrassmodule.cpp index 64e32f51932..bccd10b6563 100644 --- a/src/plugins/grass/qgsgrassmodule.cpp +++ b/src/plugins/grass/qgsgrassmodule.cpp @@ -1108,16 +1108,22 @@ void QgsGrassModule::run() // -> necessary to pass region as enviroment variable // but the feature is available in GRASS 6.1 only since 23.3.2006 + QStringList environment = QProcess::systemEnvironment(); if ( resetRegion ) { - QStringList env; - env = QProcess::systemEnvironment(); QString reg = QgsGrass::regionString( &tempWindow ); std::cerr << "reg: " << reg.ascii() << std::endl; - env.append ( "GRASS_REGION=" + reg ); - mProcess.setEnvironment ( env ); + environment.append ( "GRASS_REGION=" + reg ); } + // I was not able to get scripts working on Windows + // via QProcess and sh.exe (MinGW). g.parser runs well + // and it sets parameters correctly as enviroment variables + // but it fails (without error) to re-run the script with + // execlp(). And I could not figure out why it fails. + // Because of this problem we simulate here what g.parser + // normaly does and that way we can avoid it. + QStringList execArguments = QgsGrassModule::execArguments(mXName); if ( execArguments.size() == 0 ) @@ -1127,9 +1133,40 @@ void QgsGrassModule::run() return; } +#if defined(WIN32) + // we already know it exists from execArguments() + QString exe = QgsGrassModule::findExec ( mXName ); + QFileInfo fi ( exe ); + if ( !fi.isExecutable() ) + { + // Set enviroment variables + for ( int i = 0; i < arguments.size(); i++ ) + { + QString arg = arguments.at(i); + QString env; + if ( arg.at(0) == '-' ) //flag + { + env = "GIS_FLAG_" + QString(arg.at(0).toUpper()) + + "=1"; + } + else // option + { + QStringList opt = arg.split("="); + env = "GIS_OPT_" + opt.takeFirst().toUpper(); + env += "=" + opt.join("="); // rejoin rest + } + std::cerr << "set: " << env.ascii() << std::endl; + environment.append(env); + } + arguments.clear(); + arguments.append ( "@ARGS_PARSED@" ); + } +#endif + QString cmd = execArguments.takeFirst(); execArguments += arguments; + mProcess.setEnvironment ( environment ); mProcess.start( cmd, execArguments ); mProcess.waitForStarted();