[Haskell-cafe] Trouble with readProcess

Donn Cave donn at avvanta.com
Thu Aug 11 17:57:12 CEST 2011

Quoth Charles-Pierre Astolfi <cpa at crans.org>,

> I've found my mistake: I was calling readProcess cmd ["-p -t"] instead
> of readProcess cmd ["-p","-t"]

That would do it.

> Not sure what are the semantics of quotation in this case, though. And
> I'm pretty sure my analysis is wrong because of that :)

The principle isn't complicated. In UNIX, anyway, quotes are for the shell -
   $ cmd a b

is a string interpreted by the shell as a UNIX command (path, [args]).
If an argument contains white space or something it needs to be quoted,
and the shell supports all kinds of ways to do that.  Of course it uses
the quotes, the executed command doesn't see them.

But when a Haskell process function's command takes a list of args, 
we infer that there isn't any shell interpretation, so no quotes.
If you want a shell command, for example because you want a pipeline
or something, then you may invoke the shell yourself, like

 readProcess "/bin/sh" ["-c", "cmd -p -t"]


More information about the Haskell-Cafe mailing list