Skip to content
Permalink
Browse files

partial fix for scripts on Windows; parser works and GUI is generated…

… but run fails

git-svn-id: http://svn.osgeo.org/qgis/trunk@5121 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 30, 2006
1 parent 4e7215b commit a122c310dbd8e8f7940e7474569cde2fe8e80c9a
Showing with 84 additions and 10 deletions.
  1. +78 −9 src/plugins/grass/qgsgrassmodule.cpp
  2. +6 −1 src/plugins/grass/qgsgrassmodule.h
@@ -99,11 +99,12 @@ extern "C" {
bool QgsGrassModule::mExecPathInited = 0;
QStringList QgsGrassModule::mExecPath;

bool QgsGrassModule::inExecPath ( QString file )
QString QgsGrassModule::findExec ( QString file )
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModule::inExecPath()" << std::endl;
std::cerr << "QgsGrassModule::findExec()" << std::endl;
#endif

// Init mExecPath
// Windows searches first in current directory
if ( !mExecPathInited )
@@ -115,17 +116,40 @@ bool QgsGrassModule::inExecPath ( QString file )
mExecPath.prepend ( QgsApplication::applicationDirPath() );
mExecPathInited = true;
}

if ( QFile::exists ( file ) ) return file; // full path

// Search for module
for ( QStringList::iterator it = mExecPath.begin();
it != mExecPath.end(); ++it )
{
if ( QFile::exists ( *it + "/" + file ) )
QString full = *it + "/" + file;
if ( QFile::exists ( full ) )
{
return true;
return full;
}
}
return false;

// Not found try with .exe
#ifdef WIN32
for ( QStringList::iterator it = mExecPath.begin();
it != mExecPath.end(); ++it )
{
QString full = *it + "/" + file + ".exe";
if ( QFile::exists ( full ) )
{
return full;
}
}
#endif

return QString();
}

bool QgsGrassModule::inExecPath ( QString file )
{
if ( findExec(file).isNull() ) return false;
return true;
}

QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
@@ -182,15 +206,15 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
// => test if the module is in path and if it is not
// add .exe and test again
#ifdef WIN32
if ( inExecPath ( xName ) )
if ( inExecPath ( xName ) )
{
mXName = xName;
}
else if ( inExecPath ( xName + ".exe" ) )
{
mXName = xName + ".exe";
}
else
else
{
std::cerr << "Module " << xName.ascii() << " not found" << std::endl;
QMessageBox::warning( 0, "Warning", "Module " + xName + " not found" );
@@ -291,19 +315,64 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
std::cerr << "PATH = " << getenv ("PATH") << std::endl;
#endif

// Attention!: sh.exe (MSYS) sets $0 in scripts to file name
// without full path. Strange because when run from msys.bat
// $0 is set to full path. GRASS scripts call
// exec g.parser "$0" "$@"
// and it fails -> find and run with full path

mXName = xname;
mParent = parent;

QString exe;

#if defined(WIN32)
exe = QgsGrassModule::findExec ( xname );
if ( exe.isNull() )
{
QMessageBox::warning( 0, "Warning", "Cannot find module "
+ xname );
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";

// 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 );
process.start ( mXName, QStringList ( "--interface-description") );
process.start ( cmd, arguments );

// ? Does binary on Win need .exe extention ?
// Return code 255 (-1) was correct in GRASS < 6.1.0
if ( !process.waitForFinished()
|| (process.exitCode() != 0 && process.exitCode() != 255) )
{
std::cerr << "process.exitCode() = " << process.exitCode() << std::endl;
QMessageBox::warning( 0, "Warning", "Cannot start module " + mXName );
QMessageBox::warning( 0, "Warning", "Cannot start module " + mXName + "<br>"
+ cmd + " " + arguments.join(" ") + "<br>"
+ QString(process.readAllStandardOutput()) + "<br>"
+ QString(process.readAllStandardError()) );
return;
}
QByteArray gDescArray = process.readAllStandardOutput();
@@ -94,8 +94,13 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
static QStringList mExecPath;
static bool mExecPathInited;

// ! Find in exec path
// returns full path or null string
// appends automaticaly .exe on Windows
static QString findExec ( QString file );

// ! Check if file is in mExecPath
bool inExecPath ( QString file );
static bool inExecPath ( QString file );

public slots:
//! Run the module with current options

0 comments on commit a122c31

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