|
From: Kevin B. <kev...@bi...> - 2001-11-15 05:33:19
|
brian zimmer wrote:
> Well I'm a pessimist and I have the first bug in javaos.py.
:-) No, no - my 'stderr shows up at the end of stdout' is first. ;-)
> I'm on a Win2K box running Cygwin bash and when I execute `env` I get
> the following (abbreviated for readability):
> WINDIR=C:\WINNT
> USERPROFILE=C:\Documents and Settings\brian zimmer
> PS1=\[\033]0;\w\007
> \033[32m\]\u@\h \[\033[33m\w\033[0m\]
> $
> ANT_HOME=//d/java/third/apache/jakarta-ant-1.3
> PROGRAMFILES=C:\Program Files
> USER=bzimmer
>
> You'll notice the PS1 variable wraps to a new line and causes a
> ValueError to be thrown:
Ah, yes. I remember wondering about that case. Unfortunately, I don't know
that there's much we can do about it, except catch the ValueError and append
the value to the previous variable...
How about this?
def _getEnvironment( self ):
"""Get the environment variables by spawning a subshell.
This allows multi-line variables as long as subsequent lines do
not have '=' signs.
"""
p = self.execute( self.getEnv )
env = {}
key = 'firstLine' # in case first line had no '='
for line in self._readLines( p.getInputStream() ):
try:
i = line.index( '=' )
key = self._keyTransform(line[:i])
value = line[i+1:]
except ValueError:
# found no '=', so this line is part of previous value
value = '%s\n%s' % ( value, line )
env[ key ] = value
return env
If a subsequent line has an equals sign, this code will treat it as a new
variable assignment. We could get complex and define what characters are
valid in shell variable names, but there would still be cases where it
wouldn't work (e.g., X='My\nname=Kevin')
I think allowing some multi-line variables is useful, and handling the other
multi-liners w/o raising errors is helpful.
Thoughts?
kb
|