caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Adrien Nader <adrien@notk.org>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Martin DeMello <martindemello@gmail.com>,
	OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] [ANN] Bos 0.1.0
Date: Tue, 24 May 2016 08:49:01 +0200	[thread overview]
Message-ID: <20160524064901.GA540@notk.org> (raw)
In-Reply-To: <EBC04A884CF3423EAE5B8D541E987587@erratique.ch>

It's not really fork but Unix.open_process*.

The signatures and documentation sum up the issue:
  val open_process_in : string -> Pervasives.in_channel
  [...] The command is interpreted by the shell /bin/sh (cf. system).

As such, the process command-line needs to be properly quoted. I'm not
going to attempt to get the whole logic right so I'll only give keywords
for things that can be involved: /bin/sh, $SHELL, quoting for posix
shells, quoting for windows command-line (entirely different and 200%
ad-hoc over the course of 20 years), cmd.exe, %COMSPEC% (and probably
more things).

I see the use of a single string as the main issue because it makes
supporting the quoting for windows process invocations very difficult
(the entry point on windows gets a single string with holds every
process argument: argv in main() is actually the result of parsing...).

When spawning with a string array or string list, one isn't usually
concerned about shell escapes: only special characters such as !, ':' or
'&' might matter but the last really do not make sense in this context..

This makes it possible to quote each argument separately before merging
everything (with quoting) and call the process (NB: there are also
_exec* functions in the Microsoft CRT that could help).
I consider moving away from single-string arguments a prerequisite for
proper and sane handling of this. One annoyance for ocamlbuild is that
it exposes that same API to its plugins.

Support for wide-character functions is another change needed for better
Windows support in the OCaml ecosystem. If this has to be done with API
changes or new APIs, maybe it will be the right time to also remove
support (or not offer them at all in the new APIs) for functions that
use a single string to spawn functions.

Back to the topic, as Gabrial said, there is a number of useful
functions in ocamlbuild (see My_Unix for instance iirc) which work
fairly well and are therefore risky changes (that's actually pretty
funny logic). Nevertheless, I don't think they should stay there.

-- 
Adrien Nader


  parent reply	other threads:[~2016-05-24  6:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 21:01 Daniel Bünzli
2016-05-23 22:17 ` Martin DeMello
2016-05-23 22:43   ` Daniel Bünzli
2016-05-23 23:08     ` Gabriel Scherer
2016-05-24  6:49     ` Adrien Nader [this message]
2016-05-24 12:57 ` SP
2016-05-24 13:14   ` Daniel Bünzli
2016-05-24 14:02     ` SP

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160524064901.GA540@notk.org \
    --to=adrien@notk.org \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    --cc=martindemello@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).