[GRASS-dev] Re: [GRASS GIS] #1447: wxGUI wingrass scripts need whitespace in path

GRASS GIS trac at osgeo.org
Sat Sep 24 11:54:23 EDT 2011


#1447: wxGUI wingrass scripts need whitespace in path
------------------------------+---------------------------------------------
 Reporter:  mmetz             |       Owner:  grass-dev@…              
     Type:  defect            |      Status:  new                      
 Priority:  major             |   Milestone:  6.4.2                    
Component:  wxGUI             |     Version:  svn-releasebranch64      
 Keywords:  wingrass, spaces  |    Platform:  MSWindows XP             
      Cpu:  All               |  
------------------------------+---------------------------------------------

Comment(by mmetz):

 Replying to [comment:12 glynn]:
 > Replying to [comment:11 mmetz]:
 >
 >
 > > AFAICT, a file path without whitespaces is passed ok to the Windows
 shell (cmd.exe), but then further passed to %GRASS_SH%, yet another shell,
 and there the (by now unprotected) backslashes get lost if not quoted
 properly.
 >
 > Aha. The problem is with scripts/windows_launch.bat:
 {{{
 > @"%GRASS_SH%" -c '"%GISBASE%/scripts/SCRIPT_NAME" %*'
 }}}
 > It should be:
 {{{
 > @"%GRASS_SH%" "%GISBASE%/scripts/SCRIPT_NAME" %*
 }}}
 > The former approach can't be made to work. There is no practical way to
 write a batch file which will reliably turn a program and a list of
 arguments into a Bourne-shell command which will execute that program with
 those arguments. Any attempt will work for simple cases but fail for
 arguments which contain shell metacharacters (space, backslash, quote,
 etc). cmd.exe's string handling is too primitive to do it right.

 That was it! I tested and it works fine. A wonderfully small change to fix
 this obscure bug.
 >
 > > The strings indicating file paths do have escaping under Windows
 within the wxGUI, but it's \ that is escaped to \\, looks fine to me.
 >
 > Are you sure that it isn't Python doing this? Just to be sure, can you
 add e.g.:
 {{{
 > f = open('debug.txt', 'w')
 > f.write(repr((args, kwargs)))
 > f.close()
 }}}
 > immediately before the subprocess.Popen.__init__ call?

 > If those doubled backslashes are actually in the strings, that's a bug
 which needs to be fixed. subprocess.Popen() does the required quoting, and
 it gets it right. Note that backslashes will be doubled by repr(); if
 there are quad backslashes, that means they've really been doubled.

 The result has double, not quad backslashes, i.e. seems to be ok:
 {{{
 ((['v.in.geonames', 'input=D:\\GRASS_test_data\\IT\\IT.txt
 out=italy_geonames', 'output=IT'])), {'shell': True, 'stdin': -1,
 'stderr': -1, 'stdout': -1}]
 }}}
 >
 > I'm pretty sure that the core problem is with windows_launch.bat, as
 described above.

 You're right, thanks a lot for your help! I have committed the change to
 windows_launch.bat in 6.4 and 6.5, r48448 and r48449, respectively.

 Markus M

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/1447#comment:13>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list