Skip to content

Commit 78384a6

Browse files
author
rblazek
committed
emulate g.parser
git-svn-id: http://svn.osgeo.org/qgis/trunk@5267 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1ea018f commit 78384a6

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,16 +1108,22 @@ void QgsGrassModule::run()
11081108
// -> necessary to pass region as enviroment variable
11091109
// but the feature is available in GRASS 6.1 only since 23.3.2006
11101110

1111+
QStringList environment = QProcess::systemEnvironment();
11111112
if ( resetRegion )
11121113
{
1113-
QStringList env;
1114-
env = QProcess::systemEnvironment();
11151114
QString reg = QgsGrass::regionString( &tempWindow );
11161115
std::cerr << "reg: " << reg.ascii() << std::endl;
1117-
env.append ( "GRASS_REGION=" + reg );
1118-
mProcess.setEnvironment ( env );
1116+
environment.append ( "GRASS_REGION=" + reg );
11191117
}
11201118

1119+
// I was not able to get scripts working on Windows
1120+
// via QProcess and sh.exe (MinGW). g.parser runs well
1121+
// and it sets parameters correctly as enviroment variables
1122+
// but it fails (without error) to re-run the script with
1123+
// execlp(). And I could not figure out why it fails.
1124+
// Because of this problem we simulate here what g.parser
1125+
// normaly does and that way we can avoid it.
1126+
11211127
QStringList execArguments = QgsGrassModule::execArguments(mXName);
11221128

11231129
if ( execArguments.size() == 0 )
@@ -1127,9 +1133,40 @@ void QgsGrassModule::run()
11271133
return;
11281134
}
11291135

1136+
#if defined(WIN32)
1137+
// we already know it exists from execArguments()
1138+
QString exe = QgsGrassModule::findExec ( mXName );
1139+
QFileInfo fi ( exe );
1140+
if ( !fi.isExecutable() )
1141+
{
1142+
// Set enviroment variables
1143+
for ( int i = 0; i < arguments.size(); i++ )
1144+
{
1145+
QString arg = arguments.at(i);
1146+
QString env;
1147+
if ( arg.at(0) == '-' ) //flag
1148+
{
1149+
env = "GIS_FLAG_" + QString(arg.at(0).toUpper())
1150+
+ "=1";
1151+
}
1152+
else // option
1153+
{
1154+
QStringList opt = arg.split("=");
1155+
env = "GIS_OPT_" + opt.takeFirst().toUpper();
1156+
env += "=" + opt.join("="); // rejoin rest
1157+
}
1158+
std::cerr << "set: " << env.ascii() << std::endl;
1159+
environment.append(env);
1160+
}
1161+
arguments.clear();
1162+
arguments.append ( "@ARGS_PARSED@" );
1163+
}
1164+
#endif
1165+
11301166
QString cmd = execArguments.takeFirst();
11311167
execArguments += arguments;
11321168

1169+
mProcess.setEnvironment ( environment );
11331170
mProcess.start( cmd, execArguments );
11341171

11351172
mProcess.waitForStarted();

0 commit comments

Comments
 (0)