Skip to content

Commit

Permalink
fix for scripts on Windows
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5244 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 10, 2006
1 parent 69c0c36 commit a776fa5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 32 deletions.
89 changes: 57 additions & 32 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -152,6 +152,39 @@ bool QgsGrassModule::inExecPath ( QString file )
return true;
}

QStringList QgsGrassModule::execArguments ( QString module )
{
QString exe;
QStringList arguments;

exe = QgsGrassModule::findExec ( module );
if ( exe.isNull() )
{
return arguments;
}

#if defined(WIN32)
QFileInfo fi ( exe );
if ( fi.isExecutable() )
{
arguments.append(exe);
}
else // script
{
QString cmd = QgsApplication::applicationDirPath() + "/msys/bin/sh";
arguments.append ( cmd );

// Important! Otherwise it does not find DLL even if it is in PATH
arguments.append ( "--login" );
arguments.append ( exe );
}
#else
arguments.append(exe);
#endif

return arguments;
}

QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
QString path, QWidget * parent, const char * name, Qt::WFlags f )
:QgsGrassModuleBase ( ), mSuccess(false)
Expand Down Expand Up @@ -324,40 +357,17 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
mXName = xname;
mParent = parent;

QString exe;
QStringList arguments = QgsGrassModule::execArguments(mXName);

#if defined(WIN32)
exe = QgsGrassModule::findExec ( xname );
if ( exe.isNull() )
if ( arguments.size() == 0 )
{
QMessageBox::warning( 0, "Warning", "Cannot find module "
+ xname );
+ mXName );
return;
}
#else
exe = mXName;
#endif

QString cmd;
QStringList arguments;

#if defined(WIN32)
QFileInfo fi ( exe );
if ( fi.isExecutable() )
{
cmd = exe;
}
else // script
{
cmd = QgsApplication::applicationDirPath() + "/msys/bin/sh";
QString cmd = arguments.takeFirst();

// Important! Otherwise it does not find DLL even if it is in PATH
arguments.append ( "--login" );
arguments.append ( exe );
}
#else
cmd = exe;
#endif
arguments.append ( "--interface-description" );

QProcess process( this );
Expand Down Expand Up @@ -1098,21 +1108,36 @@ 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 env;

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 );
}
mProcess.setEnvironment ( env );

mProcess.start( mXName, arguments );
QStringList execArguments = QgsGrassModule::execArguments(mXName);

if ( resetRegion )
if ( execArguments.size() == 0 )
{
QMessageBox::warning( 0, "Warning", "Cannot find module "
+ mXName );
return;
}

QString cmd = execArguments.takeFirst();
execArguments += arguments;

mProcess.start( cmd, execArguments );

mProcess.waitForStarted();
if ( mProcess.state() != QProcess::Running )
{
QMessageBox::warning( 0, "Warning", "Cannot start module: "
+ mProcess.errorString() );
return;
}

mTabWidget->setCurrentPage(1);
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -102,6 +102,11 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
// ! Check if file is in mExecPath
static bool inExecPath ( QString file );

// ! Get executable + arguments. Executable is returned as first string.
// On Window if the module is script the executable will be path to shell
// Returns empty list if not found.
static QStringList execArguments ( QString module );

public slots:
//! Run the module with current options
void on_mRunButton_clicked() { run(); }
Expand Down

0 comments on commit a776fa5

Please sign in to comment.