rabotin wrote: > Dear all, > I'm trying to launch a grass work with a script to automate calcul. > I try successfully with calling a shell script with GRASS_BATCH_JOB > parameter (which call the test_algo.sh) > with the following shell script > > #!/bin/bash > chmod u+x $HOME/test_algo.sh > export GRASS_BATCH_JOB=$HOME/test_algo.sh > grass ~/grassdata/Roujan/simon9/ > unset GRASS_BATCH_JOB > > I'm trying now to do the same thing with a c++ program which call the > same shell script (test_algo.sh) and having the following lines (here > the .cpp file): > > #include <stdio.h> > #include <stdlib.h> > > const char chmod[]="chmod u+x /home/rabotin/test_algo.sh"; > const char expor[]="export GRASS_BATCH_JOB=/home/rabotin/test_algo.sh"; > const char grass[]="grass -text ~/grassdata/Roujan/simon9/"; > const char unset[]="unset GRASS_BATCH_JOB"; > > int main() > { > printf ("Launching grass test!"); > system(chmod); > system(expor); > system(grass); > system(unset); > printf ("Launched grass test!"); > > return 0; > } > > > But it doesnt' work well: GRASS is well launched, but no call to > test_algo.sh and GRASS doesnt' end successfully > > Can anyone have any idea to help me ?
Environment variables are per-process. Each system() call spawns a new shell process, and the export command will only affect the process in which it's run, not any other processes. From a C/C++ program, use putenv() instead, e.g.: system(chmod); putenv("GRASS_BATCH_JOB=/home/rabotin/test_algo.sh"); system(grass); -- Glynn Clements <gl...@gclements.plus.com> _______________________________________________ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user