Skip to content

File tree

2 files changed

+62
-32
lines changed

2 files changed

+62
-32
lines changed
 

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,39 @@ bool QgsGrassModule::inExecPath ( QString file )
152152
return true;
153153
}
154154

155+
QStringList QgsGrassModule::execArguments ( QString module )
156+
{
157+
QString exe;
158+
QStringList arguments;
159+
160+
exe = QgsGrassModule::findExec ( module );
161+
if ( exe.isNull() )
162+
{
163+
return arguments;
164+
}
165+
166+
#if defined(WIN32)
167+
QFileInfo fi ( exe );
168+
if ( fi.isExecutable() )
169+
{
170+
arguments.append(exe);
171+
}
172+
else // script
173+
{
174+
QString cmd = QgsApplication::applicationDirPath() + "/msys/bin/sh";
175+
arguments.append ( cmd );
176+
177+
// Important! Otherwise it does not find DLL even if it is in PATH
178+
arguments.append ( "--login" );
179+
arguments.append ( exe );
180+
}
181+
#else
182+
arguments.append(exe);
183+
#endif
184+
185+
return arguments;
186+
}
187+
155188
QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
156189
QString path, QWidget * parent, const char * name, Qt::WFlags f )
157190
:QgsGrassModuleBase ( ), mSuccess(false)
@@ -324,40 +357,17 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
324357
mXName = xname;
325358
mParent = parent;
326359

327-
QString exe;
360+
QStringList arguments = QgsGrassModule::execArguments(mXName);
328361

329-
#if defined(WIN32)
330-
exe = QgsGrassModule::findExec ( xname );
331-
if ( exe.isNull() )
362+
if ( arguments.size() == 0 )
332363
{
333364
QMessageBox::warning( 0, "Warning", "Cannot find module "
334-
+ xname );
365+
+ mXName );
335366
return;
336367
}
337-
#else
338-
exe = mXName;
339-
#endif
340368

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";
369+
QString cmd = arguments.takeFirst();
353370

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
361371
arguments.append ( "--interface-description" );
362372

363373
QProcess process( this );
@@ -1098,21 +1108,36 @@ void QgsGrassModule::run()
10981108
// -> necessary to pass region as enviroment variable
10991109
// but the feature is available in GRASS 6.1 only since 23.3.2006
11001110

1101-
QStringList env;
1102-
11031111
if ( resetRegion )
11041112
{
1113+
QStringList env;
11051114
env = QProcess::systemEnvironment();
11061115
QString reg = QgsGrass::regionString( &tempWindow );
11071116
std::cerr << "reg: " << reg.ascii() << std::endl;
11081117
env.append ( "GRASS_REGION=" + reg );
1118+
mProcess.setEnvironment ( env );
11091119
}
1110-
mProcess.setEnvironment ( env );
11111120

1112-
mProcess.start( mXName, arguments );
1121+
QStringList execArguments = QgsGrassModule::execArguments(mXName);
11131122

1114-
if ( resetRegion )
1123+
if ( execArguments.size() == 0 )
1124+
{
1125+
QMessageBox::warning( 0, "Warning", "Cannot find module "
1126+
+ mXName );
1127+
return;
1128+
}
1129+
1130+
QString cmd = execArguments.takeFirst();
1131+
execArguments += arguments;
1132+
1133+
mProcess.start( cmd, execArguments );
1134+
1135+
mProcess.waitForStarted();
1136+
if ( mProcess.state() != QProcess::Running )
11151137
{
1138+
QMessageBox::warning( 0, "Warning", "Cannot start module: "
1139+
+ mProcess.errorString() );
1140+
return;
11161141
}
11171142

11181143
mTabWidget->setCurrentPage(1);

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
102102
// ! Check if file is in mExecPath
103103
static bool inExecPath ( QString file );
104104

105+
// ! Get executable + arguments. Executable is returned as first string.
106+
// On Window if the module is script the executable will be path to shell
107+
// Returns empty list if not found.
108+
static QStringList execArguments ( QString module );
109+
105110
public slots:
106111
//! Run the module with current options
107112
void on_mRunButton_clicked() { run(); }

0 commit comments

Comments
 (0)
Please sign in to comment.