caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Sys.command and quotes
@ 2009-05-05  8:58 Matthieu Dubuget
  2009-05-05  9:37 ` [Caml-list] " Francois Pottier
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Matthieu Dubuget @ 2009-05-05  8:58 UTC (permalink / raw)
  To: caml-list

Hello,

I have a problem with mingw version of ocaml (compiled by hand, or with 
godi).

1- Is the following reproducible?

2- If yes, do you consider this as a bug?

It seems that in "Sys.command s", if the first and the last characters 
of s are '"', they are elided?

It prevents menhir (20090402) to compile on my mingw system with 
ocamlfind in use (because when
ocamlfind is used, the dependencies are found with an ocamlfind ocamldep 
call).

Thanks in advance


Objective Caml version 3.11.0

# let cmd = "echo";;
val cmd : string = "echo"
# let arg1 = "Hello world";;
val arg1 : string = "Hello world"
# let q = Filename.quote;;
val q : string -> string = <fun>
# let go c = Sys.command (String.concat " " c);;
val go : string list -> int = <fun>
# go [cmd;arg1];;
Hello world
- : int = 0
# go [q cmd; arg1];;
Hello world
- : int = 0
# go [cmd; q arg1];;
"Hello world"
- : int = 0
# go [q cmd; q arg1];;
'echo" "Hello' n'est pas reconnu en tant que commande interne
ou externe, un programme ex‚cutable ou un fichier de commandes.
- : int = 1








^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Sys.command and quotes
  2009-05-05  8:58 Sys.command and quotes Matthieu Dubuget
@ 2009-05-05  9:37 ` Francois Pottier
  2009-05-05 19:59   ` Matthieu Dubuget
  2009-05-05  9:44 ` Olivier Andrieu
  2009-05-05  9:45 ` Sylvain Le Gall
  2 siblings, 1 reply; 5+ messages in thread
From: Francois Pottier @ 2009-05-05  9:37 UTC (permalink / raw)
  To: Matthieu Dubuget; +Cc: caml-list, Yann Régis-Gianas


Hello,

On Tue, May 05, 2009 at 10:58:29AM +0200, Matthieu Dubuget wrote:
> It prevents menhir (20090402) to compile on my mingw system with ocamlfind
> in use (because when ocamlfind is used, the dependencies are found with an
> ocamlfind ocamldep call).

I don't know whether it is a bug in Sys.command; anyway, the latest release of
Menhir (20090505) attempts to work around it:

  http://cristal.inria.fr/~fpottier/menhir/menhir-20090505.tar.gz

(I should have released this earlier, but forgot, so here it is, released
two minutes ago :)

-- 
François Pottier
Francois.Pottier@inria.fr
http://cristal.inria.fr/~fpottier/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Sys.command and quotes
  2009-05-05  8:58 Sys.command and quotes Matthieu Dubuget
  2009-05-05  9:37 ` [Caml-list] " Francois Pottier
@ 2009-05-05  9:44 ` Olivier Andrieu
  2009-05-05  9:45 ` Sylvain Le Gall
  2 siblings, 0 replies; 5+ messages in thread
From: Olivier Andrieu @ 2009-05-05  9:44 UTC (permalink / raw)
  To: Matthieu Dubuget; +Cc: caml-list

On Tue, May 5, 2009 at 10:58, Matthieu Dubuget
<matthieu.dubuget@gmail.com> wrote:
> Hello,
>
> I have a problem with mingw version of ocaml (compiled by hand, or with
> godi).
>
> 1- Is the following reproducible?
>
> 2- If yes, do you consider this as a bug?
>
> It seems that in "Sys.command s", if the first and the last characters of s
> are '"', they are elided?

that's probably just the Windows command interpreter behaviour.
Sys.command calls the C library system() function which ends up
calling CMD.EXE. This one has an utterly byzantine behavior concerning
quotations marks.

cf. http://technet.microsoft.com/en-us/library/bb490880.aspx

« Processing quotation marks

If you specify /c or /k, cmd processes the remainder of string and
quotation marks are preserved only if all of the following conditions
are met:

    * You do not use /s.
    * You use exactly one set of quotation marks.
    * You do not use any special characters within the quotation marks
(for example: &<>( ) @ ^ |).
    * You use one or more white-space characters within the quotation marks.
    * The string within quotation marks is the name of an executable file.

If the previous conditions are not met, string is processed by
examining the first character to verify whether or not it is an
opening quotation mark. If the first character is an opening quotation
mark, it is stripped along with the closing quotation mark. Any text
following the closing quotation marks is preserved.
»

IIRC a sort of workaround is to always add extra " in your command line:
  go ["\"" ; .... ; "\""]

good luck
-- 
  Olivier


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Sys.command and quotes
  2009-05-05  8:58 Sys.command and quotes Matthieu Dubuget
  2009-05-05  9:37 ` [Caml-list] " Francois Pottier
  2009-05-05  9:44 ` Olivier Andrieu
@ 2009-05-05  9:45 ` Sylvain Le Gall
  2 siblings, 0 replies; 5+ messages in thread
From: Sylvain Le Gall @ 2009-05-05  9:45 UTC (permalink / raw)
  To: caml-list

Hello,

On 05-05-2009, Matthieu Dubuget <matthieu.dubuget@gmail.com> wrote:
> Hello,
>
> I have a problem with mingw version of ocaml (compiled by hand, or with 
> godi).
>
> 1- Is the following reproducible?
>
> 2- If yes, do you consider this as a bug?
>
> It seems that in "Sys.command s", if the first and the last characters 
> of s are '"', they are elided?
>

In fact, I have done some testing about this sometimes ago and comme to
the conclusion that "-handling on windows is quite weird. If and only if
there is a space (or other problematic char) in your commannd/arg name
you can use quoting. Otherwise it will be reported as an error.

I think it is not directly related to OCaml.

Maybe, I am not totaly right with my conclusion, but I can give you a
simple tips: 

Use Unix.create_process et al that take array as arguments. It always
use the good quoting.

Regards
Sylvain Le Gall


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Sys.command and quotes
  2009-05-05  9:37 ` [Caml-list] " Francois Pottier
@ 2009-05-05 19:59   ` Matthieu Dubuget
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Dubuget @ 2009-05-05 19:59 UTC (permalink / raw)
  To: caml-list

Francois Pottier a écrit :
> Hello,
> 
> On Tue, May 05, 2009 at 10:58:29AM +0200, Matthieu Dubuget wrote:
>> It prevents menhir (20090402) to compile on my mingw system with ocamlfind
>> in use (because when ocamlfind is used, the dependencies are found with an
>> ocamlfind ocamldep call).
> 
> I don't know whether it is a bug in Sys.command; anyway, the latest release of
> Menhir (20090505) attempts to work around it:
> 
>   http://cristal.inria.fr/~fpottier/menhir/menhir-20090505.tar.gz
> 
> (I should have released this earlier, but forgot, so here it is, released
> two minutes ago :)
> 

;-)

Thanks!

This solves the installation problem. Both with my manual installation
and with GODI (a push in godi repository would be nice, please).

I still have some problems when using the godi version of the
development system (dependencies of some .mly file failing).
More on this problem when I will have the time to investigate.

Salutations

Matt



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-05-05 19:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-05  8:58 Sys.command and quotes Matthieu Dubuget
2009-05-05  9:37 ` [Caml-list] " Francois Pottier
2009-05-05 19:59   ` Matthieu Dubuget
2009-05-05  9:44 ` Olivier Andrieu
2009-05-05  9:45 ` Sylvain Le Gall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).