[GRASS-dev] [GRASS-SVN] r60679 - grass/trunk/lib/python/script
Glynn Clements
glynn at gclements.plus.com
Wed Jul 2 16:35:24 PDT 2014
Anna Petrášová wrote:
> > It's because it can't find v.in.gps. I suggest to add to the patch
> something like this:
>
> + def __init__(self, args, **kwargs):
> + if ( sys.platform == 'win32'
> + and isinstance(args, list)
> + and not kwargs.get('shell', False)
> + and kwargs.get('executable') is None ):
> + cmd = shutil_which(args[0])
> if cmd is None:
> raise OSError
> + args = [cmd] + args[1:]
> + name, ext = os.path.splitext(cmd)
> + if ext.lower() not in self._builtin_exts:
> + kwargs['shell'] = True
> + args = [self._escape_for_shell(arg) for arg in args]
> + subprocess.Popen.__init__(self, args, **kwargs)
Hmm; maybe:
def __init__(self, args, **kwargs):
if ( sys.platform == 'win32'
and isinstance(args, list)
and not kwargs.get('shell', False)
and kwargs.get('executable') is None ):
cmd = shutil_which(args[0])
if cmd is not None:
args = [cmd] + args[1:]
name, ext = os.path.splitext(cmd)
if ext.lower() not in self._builtin_exts:
kwargs['shell'] = True
args = [self._escape_for_shell(arg) for arg in args]
subprocess.Popen.__init__(self, args, **kwargs)
If shutil_which() doesn't find the command, we just leave it to
Popen() to complain about it. It's conceivable that it might even
manage to run it (I wouldn't assume that shutil_which() mimics
Windows' own handling exactly).
Ideally, I'd prefer our version of Popen to be as close to the
original as we can get away with.
Alternatively.
def __init__(self, args, **kwargs):
if ( sys.platform == 'win32'
and isinstance(args, list)
and not kwargs.get('shell', False)
and kwargs.get('executable') is None ):
cmd = shutil_which(args[0])
if cmd is not None:
args = [cmd] + args[1:]
name, ext = os.path.splitext(cmd)
else:
name, ext = None, ''
if ext.lower() not in self._builtin_exts:
kwargs['shell'] = True
args = [self._escape_for_shell(arg) for arg in args]
subprocess.Popen.__init__(self, args, **kwargs)
In this case, it falls back to using the shell if shutil_which()
fails, while still keeping the shell out of the way for an EXE.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list