GRASS and windows console: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(remove useless info from the selecting a shell section. note - this section not valid until next release)
 
(5 intermediate revisions by the same user not shown)
Line 50: Line 50:
</source>
</source>


== selecting a shell ==
== selecting a different shell ==
On windows, in the absence of the environmental variable GRASS_SH, the grass startup script selects the shell specified in environment variable ComSpec.  This is typically cmd.sh.
On MS Windows, in the absence of the environmental variable GRASS_SH, the grass startup script selects the shell specified in environment variable ComSpec.  This is typically ''cmd.exe''.
The default shell can be overridden by setting the environment variable GRASS_SH. To make powershell the startup command shell set the environment variable with
 
<source lang="bat">
<source lang="bat">
GRASS_SH=%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
REM check shell
echo %ComSpec%
C:\WINDOWS\system32\cmd.exe
</source>
</source>
The default shell can be overridden by setting the environment variable GRASS_SH.
To make [https://en.wikipedia.org/wiki/PowerShell MS powershell] the startup command shell set the environment variable with
<source lang="bat">
SET GRASS_SH=%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
</source>
in ''C:\OSGeo4W64\apps\grass\grass-7.7.svn\etc\env.bat'' (e.g. for OSGeo4W 64bit).


[[Category: Development]]
[[Category: Development]]
[[Category: FAQ]]
[[Category: FAQ]]
[[Category: WinGRASS]]
[[Category: WinGRASS]]

Latest revision as of 19:44, 23 December 2018

This page shows extended examples how to run GRASS modules in the winGRASS windows console

Windows batch files in GRASS

In order to ease the workflow of analysis, several GRASS modules can be invoked at once by an batch file (*.bat) in the winGRASS windows console.

Python grass modules (e.g. v.db.addcolumn) have to be invoked by call in the batch-file.

@ECHO ON
g.region -p
v.in.region output=myreg
call v.db.addtable map=myreg
call v.db.addcolumn map=myreg columns="col1 double"
v.to.db map=myreg option=area columns=col1

Running batch files without starting up GRASS:

"%ProgramFiles?%\QGIS 2.18\bin\Grass72.bat" --exec MyScript.bat D:/myGrassData/MyLoc/MyMapset

g.list output as input for another GRASS module

Using g.list output as input variable for another module, e.g. to remove a list raster map.

FOR /F %c in ('g.list "type=raster" "pattern=*2" "mapset=user1" "separator=comma"') DO SET RASTER2REMOVE=%c

echo %RASTER2REMOVE%
b172,d172,it172,r172

g.remove type=raster name=%RASTER2REMOVE%
The following data base element files would be deleted:
raster/b172@user1
raster/d172@user1
raster/it172@user1
raster/r172@user1
WARNING: Nothing removed. You must use the force flag (-f) to actually
         remove them. Exiting.

Using g.list output as input variable for another module, e.g. to loop through a list of vector maps and buffer them.

FOR /F %c IN ('g.list "type=vector" "separator=comma"') DO SET VECTLIST=%c

FOR %g IN (%VECTLIST%) DO v.buffer input=%g output=%g_buffer_200 distance=200

selecting a different shell

On MS Windows, in the absence of the environmental variable GRASS_SH, the grass startup script selects the shell specified in environment variable ComSpec. This is typically cmd.exe.

REM check shell
echo %ComSpec%
C:\WINDOWS\system32\cmd.exe

The default shell can be overridden by setting the environment variable GRASS_SH.

To make MS powershell the startup command shell set the environment variable with

SET GRASS_SH=%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

in C:\OSGeo4W64\apps\grass\grass-7.7.svn\etc\env.bat (e.g. for OSGeo4W 64bit).