Problem with ghc on Windows ME
Simon Marlow
simonmar at microsoft.com
Thu Jan 29 14:53:21 EST 2004
After Googling around a bit, I found this description of exactly how
Windows interprets command lines in the C runtime:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng
/htm/progs_12.asp
As you can see, the rules are indeed very strange, but they are
invertible. I think this code should do the trick:
translate :: String -> String
translate str = '"' : snd (foldr escape (True,"\"") str)
where escape '"' (_, str) = (True, '\\' : '"' : str)
escape '\\' (True, str) = (True, '\\' : '\\' : str)
escape '\\' (False, str) = (False, '\\' : str)
escape c (_, str) = (False, c : str)
Cheers,
Simon
> -----Original Message-----
> From: glasgow-haskell-users-bounces at haskell.org
> [mailto:glasgow-haskell-users-bounces at haskell.org] On Behalf
> Of Simon Marlow
> Sent: 29 January 2004 11:31
> To: Claus Reinke; Simon Peyton-Jones;
> glasgow-haskell-users at haskell.org
> Subject: RE: Problem with ghc on Windows ME
>
>
> > So does that mean functionality has been lost in the move from
> > ghc-6.0.1?
>
> No, the behaviour is improved in 6.2 because we're now
> careful to escape
> quotes before passing the command-line to the operating system.
>
> I think confusion has arisen because Simon pointed out that there's no
> way, on Windows, to pass this sequence of characters as an
> argument to a
> command:
>
> \"
>
> This is not entirely true, I just discovered that the
> sequence \\\" will
> turn into \". But in general, the sequence \\ does not turn into \.
> Windows' command-line quoting rules are highly mysterious, to say the
> least.
>
> So the patch I posted is not complete. It looks like rawSystem should
> additionally translate \" as \\\".
>
> > Because that (on win98) happily accepts such useful
> > contraptions as
> >
> > System.Cmd.rawSystem "\"c:\\silly
> > space\\Vim\\vim62\\gvim.exe\" --servername GVIM --remote-send
> > \":echo \\\"hi \\\\\\\" there\\\"<cr>\"" >>= print
>
> The idea is that you should pass to rawSystem *exactly* the
> command and
> arguments you want to run, with no quoting except that required by the
> Haskell lexical syntax. You'll notice that rawSystem now takes the
> command and list of arguments separately in 6.2. The
> implementation of
> rawSystem will attempt to compensate for the internal translation that
> Windows does on the command-line; on Unix no translation is necessary.
> So clients of rawSystem should be more portable, because they
> don't have
> to know about quoting that happens under the hood.
>
> Your example will probably work once it's reformulated for
> 6.2's version
> of rawSystem, and once we fix rawSystem in light of the \\\" hack I
> discovered above.
>
> Cheers,
> Simon
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
More information about the Glasgow-haskell-users
mailing list