On 05 April 2005 20:33, Claus Reinke wrote:

> Let me see if I get the call-chain correct (System.-prefix omitted):
> 
>     Cmd.rawSystem -> Process.runProcess ->
>     Process.Internals.runProcessWin32
> 
>     Cmd.system -> Process.runCommand ->
>     Process.Internals.commandToProcess +
>     Process.Internals.runProcessWin32
> 
> The first thing I notice is that commandToProcess doesn't do
> much (well, now it tries to find a command interpreter, but it does
> no translation) - both variants go through runProcessWin32,
> which calls Process.Internals.translate! Is that intended??
>
> It looks like a bug to attempt counter-translation for Cmd.system?

If you look closely, you'll see that translate isn't applied to the
argument to runCommand.  There's no double-translation going on, we just
pass the command line directly to cmd.exe/command.com.

rawSystem needs to convert the [String] parameters into a single string
for passing to CreateProcess.  I'm pretty sure that translate is doing
the right thing here, at least if the target process is using the
standard command-line parser from Microsoft's C runtime.

It seems that command.com has non-standard command-line parsing, so it
won't work with rawSystem.  In fact on Windows, runCommand is really
more "raw" than rawSystem, because it does no translation.

The translation could be made to avoid using quotes in cases where
quotes aren't necessary.  But you can't avoid quoting in general, so
this wouldn't be a proper fix.

So I propose the following:

  - we document that rawSystem doesn't work well if you're
    invoking command.com or cmd.exe on Windows: use runCommand
    insteead.

  - we could provide a way to access runProcessWin32 directly,
    which gives you a more "raw" interface to CreateProcess
    on Windows (non-portable, of course).

> As an experiment, I created my own version of the rawSystem-chain,
> replacing the call to translate for the args in runProcessWin32 with
> a call to id, and that seems to be sufficient to solve this problem:
> 
... snip...
>
> whether this creates any other issues I don't know:-)

It'll break invoking programs other than command.com with rawSystem.  We
spent quite a bit of time getting this right - the best way to test it
is to build your own 'echo' program, and try invoking that using
rawSystem passing arguments involving quotes, spaces and backslashes.
The echo program should see the arguments exactly as you passed them to
rawSystem.
 
Cheers,
        Simon
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to