@@ -1108,16 +1108,22 @@ void QgsGrassModule::run()
1108
1108
// -> necessary to pass region as enviroment variable
1109
1109
// but the feature is available in GRASS 6.1 only since 23.3.2006
1110
1110
1111
+ QStringList environment = QProcess::systemEnvironment ();
1111
1112
if ( resetRegion )
1112
1113
{
1113
- QStringList env;
1114
- env = QProcess::systemEnvironment ();
1115
1114
QString reg = QgsGrass::regionString ( &tempWindow );
1116
1115
std::cerr << " reg: " << reg.ascii () << std::endl;
1117
- env.append ( " GRASS_REGION=" + reg );
1118
- mProcess .setEnvironment ( env );
1116
+ environment.append ( " GRASS_REGION=" + reg );
1119
1117
}
1120
1118
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
+
1121
1127
QStringList execArguments = QgsGrassModule::execArguments (mXName );
1122
1128
1123
1129
if ( execArguments.size () == 0 )
@@ -1127,9 +1133,40 @@ void QgsGrassModule::run()
1127
1133
return ;
1128
1134
}
1129
1135
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
+
1130
1166
QString cmd = execArguments.takeFirst ();
1131
1167
execArguments += arguments;
1132
1168
1169
+ mProcess .setEnvironment ( environment );
1133
1170
mProcess .start ( cmd, execArguments );
1134
1171
1135
1172
mProcess .waitForStarted ();
0 commit comments