@@ -99,11 +99,12 @@ extern "C" {
99
99
bool QgsGrassModule::mExecPathInited = 0 ;
100
100
QStringList QgsGrassModule::mExecPath ;
101
101
102
- bool QgsGrassModule::inExecPath ( QString file )
102
+ QString QgsGrassModule::findExec ( QString file )
103
103
{
104
104
#ifdef QGISDEBUG
105
- std::cerr << " QgsGrassModule::inExecPath ()" << std::endl;
105
+ std::cerr << " QgsGrassModule::findExec ()" << std::endl;
106
106
#endif
107
+
107
108
// Init mExecPath
108
109
// Windows searches first in current directory
109
110
if ( !mExecPathInited )
@@ -115,17 +116,40 @@ bool QgsGrassModule::inExecPath ( QString file )
115
116
mExecPath .prepend ( QgsApplication::applicationDirPath () );
116
117
mExecPathInited = true ;
117
118
}
119
+
120
+ if ( QFile::exists ( file ) ) return file; // full path
118
121
119
122
// Search for module
120
123
for ( QStringList::iterator it = mExecPath .begin ();
121
124
it != mExecPath .end (); ++it )
122
125
{
123
- if ( QFile::exists ( *it + " /" + file ) )
126
+ QString full = *it + " /" + file;
127
+ if ( QFile::exists ( full ) )
124
128
{
125
- return true ;
129
+ return full ;
126
130
}
127
131
}
128
- return false ;
132
+
133
+ // Not found try with .exe
134
+ #ifdef WIN32
135
+ for ( QStringList::iterator it = mExecPath .begin ();
136
+ it != mExecPath .end (); ++it )
137
+ {
138
+ QString full = *it + " /" + file + " .exe" ;
139
+ if ( QFile::exists ( full ) )
140
+ {
141
+ return full;
142
+ }
143
+ }
144
+ #endif
145
+
146
+ return QString ();
147
+ }
148
+
149
+ bool QgsGrassModule::inExecPath ( QString file )
150
+ {
151
+ if ( findExec (file).isNull () ) return false ;
152
+ return true ;
129
153
}
130
154
131
155
QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
@@ -182,15 +206,15 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
182
206
// => test if the module is in path and if it is not
183
207
// add .exe and test again
184
208
#ifdef WIN32
185
- if ( inExecPath ( xName ) )
209
+ if ( inExecPath ( xName ) )
186
210
{
187
211
mXName = xName;
188
212
}
189
213
else if ( inExecPath ( xName + " .exe" ) )
190
214
{
191
215
mXName = xName + " .exe" ;
192
216
}
193
- else
217
+ else
194
218
{
195
219
std::cerr << " Module " << xName.ascii () << " not found" << std::endl;
196
220
QMessageBox::warning ( 0 , " Warning" , " Module " + xName + " not found" );
@@ -291,19 +315,64 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
291
315
std::cerr << " PATH = " << getenv (" PATH" ) << std::endl;
292
316
#endif
293
317
318
+ // Attention!: sh.exe (MSYS) sets $0 in scripts to file name
319
+ // without full path. Strange because when run from msys.bat
320
+ // $0 is set to full path. GRASS scripts call
321
+ // exec g.parser "$0" "$@"
322
+ // and it fails -> find and run with full path
323
+
294
324
mXName = xname;
295
325
mParent = parent;
326
+
327
+ QString exe;
328
+
329
+ #if defined(WIN32)
330
+ exe = QgsGrassModule::findExec ( xname );
331
+ if ( exe.isNull () )
332
+ {
333
+ QMessageBox::warning ( 0 , " Warning" , " Cannot find module "
334
+ + xname );
335
+ return ;
336
+ }
337
+ #else
338
+ exe = mXName ;
339
+ #endif
340
+
341
+ QString cmd;
342
+ QStringList arguments;
343
+
344
+ #if defined(WIN32)
345
+ QFileInfo fi ( exe );
346
+ if ( fi.isExecutable () )
347
+ {
348
+ cmd = exe;
349
+ }
350
+ else // script
351
+ {
352
+ cmd = QgsApplication::applicationDirPath () + " /msys/bin/sh" ;
353
+
354
+ // Important! Otherwise it does not find DLL even if it is in PATH
355
+ arguments.append ( " --login" );
356
+ arguments.append ( exe );
357
+ }
358
+ #else
359
+ cmd = exe;
360
+ #endif
361
+ arguments.append ( " --interface-description" );
296
362
297
363
QProcess process ( this );
298
- process.start ( mXName , QStringList ( " --interface-description " ) );
364
+ process.start ( cmd, arguments );
299
365
300
366
// ? Does binary on Win need .exe extention ?
301
367
// Return code 255 (-1) was correct in GRASS < 6.1.0
302
368
if ( !process.waitForFinished ()
303
369
|| (process.exitCode () != 0 && process.exitCode () != 255 ) )
304
370
{
305
371
std::cerr << " process.exitCode() = " << process.exitCode () << std::endl;
306
- QMessageBox::warning ( 0 , " Warning" , " Cannot start module " + mXName );
372
+ QMessageBox::warning ( 0 , " Warning" , " Cannot start module " + mXName + " <br>"
373
+ + cmd + " " + arguments.join (" " ) + " <br>"
374
+ + QString (process.readAllStandardOutput ()) + " <br>"
375
+ + QString (process.readAllStandardError ()) );
307
376
return ;
308
377
}
309
378
QByteArray gDescArray = process.readAllStandardOutput ();
0 commit comments