Skip to content
Permalink
Browse files

fix for scripts on Windows

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5244 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Apr 10, 2006
1 parent 86846de commit cf46194799e96cf62f4436780679045632b9afed
Showing with 62 additions and 32 deletions.
  1. +57 −32 src/plugins/grass/qgsgrassmodule.cpp
  2. +5 −0 src/plugins/grass/qgsgrassmodule.h
@@ -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)
@@ -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 );
@@ -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);
@@ -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(); }

0 comments on commit cf46194

Please sign in to comment.
You can’t perform that action at this time.