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

GRASS GIS trac at osgeo.org
Fri Sep 23 15:05:56 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 glynn):

 Replying to [comment:8 mmetz]:

 > The *args argument to subprocess.Popen [0] is a list of arguments.

 Note: args is a list of Popen's non-keyword arguments. args[0] should be a
 list containing the program's arguments. len(args) should always be 1; all
 arguments except for the first one ("args") should be passed as keyword
 arguments, not positional arguments.

 While subprocess.Popen()'s first argument can be a string, this feature
 probably shouldn't be used. It's too easy to get it wrong.

 > subprocess.Popen converts the arguments differently, depending on
 whether there is whitespace in an argument or not.

 subprocess.Popen() has to convert the argument list to a command string
 according to the rules by which MSVCRT parses the command string into
 arguments, so that the program's main() ends up seeing the correct argv[].
 One of those rules is that strings containing whitespace must be quoted.

 Because the underlying Windows interface (!CreateProcess) treats a command
 line as a string, rather than as a list of strings (as is the case for
 Unix' execve()), there isn't any 100% reliable way of ensuring that the
 program gets the correct argv[] passed to its main() function
 (historically, DOS programs were often written in assembler and didn't
 have a main(), while Windows programs use !WinMain rather than main()).
 The best that you can do is to assume that the program parses the command
 line according to the MSVCRT rules (there's a URL in the subprocess.py
 file). If it doesn't, you lose.

 > The result is meant as input for programs and apparently sometimes
 incompatible with "sh -c <grass.module> <arguments>". The problem for file
 input arguments arises if there is no whitespace in there because sh
 removes all backslashes left over by subprocess.Popen. The workaround is
 to convert the *args list into one long string with whitespaces, file
 paths quoted earlier when creating the command:

 Before attempting this, first please confirm that the data being passed to
 `subprocess.Popen.__init__` by gcmd.Popen() is actually correct. len(args)
 should be 1, args[0] should be a list of strings, none of those strings
 should have any quoting or escaping (beware of Python's own
 quoting/escaping if repr() is used). If this isn't the case, then the
 problem lies elsewhere, and trying to correct for it in gcmd.Popen would
 actually mean introducing an "equal but opposite" bug.

 Second, ensure that any "fix" for shell scripts DOESN'T go into 7.0. On
 Windows, 7.0 needs to work with binaries, Python scripts and (cmd.exe)
 batch files, and it needs to do so reliably. If that means that it doesn't
 work with bash scripts, tough.

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



More information about the grass-dev mailing list