[GRASS-dev] [GRASS GIS] #3170: GRASS_BATCH_JOB does not tolerate path with spaces

GRASS GIS trac at osgeo.org
Mon Sep 3 15:32:30 PDT 2018


#3170: GRASS_BATCH_JOB does not tolerate path with spaces
-------------------------+-------------------------------------------------
  Reporter:  marisn      |      Owner:  wenzeslaus
      Type:  defect      |     Status:  new
  Priority:  normal      |  Milestone:  7.6.0
 Component:  Startup     |    Version:  svn-trunk
Resolution:              |   Keywords:  grass.py init spaces exec
       CPU:              |  GRASS_BATCH_JOB Popen shell=True
  Unspecified            |   Platform:  Unspecified
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

 * owner:  grass-dev@… => wenzeslaus
 * keywords:  grass.py, init => grass.py init spaces exec GRASS_BATCH_JOB
     Popen shell=True
 * milestone:  7.2.4 => 7.6.0


Comment:

 For 7.2 and 7.4 (and maybe 7.6) the workarounds are:

 1. Don't use `GRASS_BATCH_JOB`, use more powerful `--exec` instead.
 2. Don't use spaces in the path. (And please let us know why do you prefer
 `GRASS_BATCH_JOB` rather over `--exec`.)

 The spaces-in-path support can be implemented like this:

 {{{
 #!diff
 Index: lib/init/grass.py
 ===================================================================
 --- lib/init/grass.py   (revision 73229)
 +++ lib/init/grass.py   (working copy)
 @@ -1511,9 +1511,17 @@
      batch_job_string = batch_job
      if not isinstance(batch_job, string_types):
          batch_job_string = ' '.join(batch_job)
      message(_("Executing <%s> ...") % batch_job_string)
      if isinstance(batch_job, string_types):
 +        def quote(string):
 +            if '"' in string:
 +                return "'%s'" % batch_job
 +            else:
 +                return '"%s"' % batch_job
 +        batch_job = quote(batch_job)
          proc = Popen(batch_job, shell=True)
      else:
          try:
 }}}

 Here `shell=True` (which is splitting the command using spaces) is used
 because it was used with `GRASS_BATCH_JOB` in the past. `--exec` is not
 using `shell=True` and allows spaces. Note that for 8.0 there might be
 changes to `GRASS_BATCH_JOB` in order to make it more aligned with
 `--exec` (see wiki:Grass8Planning).

 ''Milestone is 7.6 or 7.8.''

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/3170#comment:6>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list