[GRASS-user] Using shell and perl scripts via a python script in windows, or better change to Linux?

Hello,

I’ve started to develop some pre-processing steps for a hydrological model using python scripts with winGRASS 6.4. Now, I got some very useful shell and perl scripts including Grass functions developed under Linux, which I wanted to use.

Does anybody know if it is possible to start these scripts from a python script under windows?

There are more than 50 scripts, which depend on each other, and I don’t have the time to translate them to python (I still have to develop my hydrological model). So, I’m looking for the fastest way.

1) Is it in this case better to change to Linux? Can I run these shell and perl scripts easily with python in Linux?

2) Would it be better to adapt these scripts to the windows environment? In this case, what would have to be changed? (I don’t know shell, nor perl)

Many thanks for any hint!

Sonja

Maybe I gave up to early, but my solution is the change to Linux.
I finally got my python scripts, which call the Geomhydas shell and perl
scripts, to work.
I wrote some documentation:

How to run Python/Shell/Perl scripts in combination with Grass under Linux
(here tested for Debian)

1. Install Grass6.4 for the corresponding Linux version
2. Install Python2.6

Scripts Geo-Mhydas (in Perl and Shell)
- create folder segmentation in home/user/
- give you administrator rights in this folder
- copy the scripts inside this folder

Environment variables to set:
The following paragraph has to be added at the end of the file .bashrc
(which is located as hidden file in home/user/. A hidden file can be seen
and modified in an editor à open à right click in this window à mark show
hidden files)
Then edit:

export GISBASE=usr/lib/grass64
export
PATH=$PATH:/home/user/segmentation:/$GISBASE/bin:/$GISBASE/scripts:/$GISBASE/etc:/$GISBASE/lib:/usr/lib/python2.5:/$GISBASE/etc/python/grass:/$GISBASE/etc/python/grass/lib:/$GISBASE/etc/python/grass/script
export GISRC=$HOME/.grassrc6
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
export PYTHONPATH=$GISBASE/etc/python
export PYTHONLIB=/usr/lib/python2.5

export GIS_LOCK=$$

Replace user with your user name.
Linux has to be restarted in order to consider these variables.
You can check if the variables are right in the terminal with:

echo $PATH

The variables should contain the values shown above. $GISBASE is a variable,
if it is not recognised correctly, just replace it by its value in the
following variables.

Once restarted you can start Grass via the terminal with the command
grass64.

The Python scripts should look as follows and have to contain the first
line.

#!usr/bin/env python

import grass.script as grass

'''Affiche le contenu du mapset'''
'''Display the mapset'''
env = grass.gisenv()
print env
vectors = grass.read_command("g.list", type='vect')
print vectors

filvoirie=raw_input("Please enter the name of the input vector (line) file :
")
grass.run_command("m.disline", input=filvoirie, output='filvoirie_disline',
length='10',overwrite=True)

Save the script as script.py

Here m.disline is a combination of shell and perl scripts of Geo-Mhydas.

To run the python script go to your terminal where you started Grass.

Type python /location of script/script.py

And watch your program execute!

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Using-shell-and-perl-scripts-via-a-python-script-in-windows-or-better-change-to-Linux-tp5317271p5328961.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On Friday 23 of July 2010 11:58:54 sonja1 wrote:

Maybe I gave up to early, but my solution is the change to Linux.
I finally got my python scripts, which call the Geomhydas shell and perl
scripts, to work.
I wrote some documentation:

How to run Python/Shell/Perl scripts in combination with Grass under Linux
(here tested for Debian)

1. Install Grass6.4 for the corresponding Linux version
2. Install Python2.6

Scripts Geo-Mhydas (in Perl and Shell)
- create folder segmentation in home/user/
- give you administrator rights in this folder
- copy the scripts inside this folder

Environment variables to set:
The following paragraph has to be added at the end of the file .bashrc
(which is located as hidden file in home/user/. A hidden file can be seen
and modified in an editor à open à right click in this window à mark show
hidden files)
Then edit:

export GISBASE=usr/lib/grass64
export
PATH=$PATH:/home/user/segmentation:/$GISBASE/bin:/$GISBASE/scripts:/$GISBAS
E/etc:/$GISBASE/lib:/usr/lib/python2.5:/$GISBASE/etc/python/grass:/$GISBASE
/etc/python/grass/lib:/$GISBASE/etc/python/grass/script export
GISRC=$HOME/.grassrc6
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
export PYTHONPATH=$GISBASE/etc/python
export PYTHONLIB=/usr/lib/python2.5

export GIS_LOCK=$$

Replace user with your user name.
Linux has to be restarted in order to consider these variables.
You can check if the variables are right in the terminal with:

echo $PATH

The variables should contain the values shown above. $GISBASE is a
variable, if it is not recognised correctly, just replace it by its value
in the following variables.

Once restarted you can start Grass via the terminal with the command
grass64.

The Python scripts should look as follows and have to contain the first
line.

#!usr/bin/env python

import grass.script as grass

'''Affiche le contenu du mapset'''
'''Display the mapset'''
env = grass.gisenv()
print env
vectors = grass.read_command("g.list", type='vect')
print vectors

filvoirie=raw_input("Please enter the name of the input vector (line) file
: ")
grass.run_command("m.disline", input=filvoirie, output='filvoirie_disline',
length='10',overwrite=True)

Save the script as script.py

Here m.disline is a combination of shell and perl scripts of Geo-Mhydas.

To run the python script go to your terminal where you started Grass.

Type python /location of script/script.py

And watch your program execute!

A candidate for the wiki, right?
Thanks, Nikos

Yes. I already thought about putting it into the wiki. However, I have lots
of stuff to do at the moment and I wanted to check if really all of the
named environment variables are necessary.
I will work on it as soon as I find some time.

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Using-shell-and-perl-scripts-via-a-python-script-in-windows-or-better-change-to-Linux-tp5317271p5336900.html
Sent from the Grass - Users mailing list archive at Nabble.com.