Trouble with readProcess

Hi -cafe, I'm using readProcess and I don't know how to handle this issue: readProcess cmd [opt1,opt2] seems to execute the following: $ cmd "opt1" "opt2" That is usually fine, but I'm using an external program that doesn't understand the quotes, so I need to execute instead: $ cmd opt1 opt2 How should I do that? -- Cp

Quoth Charles-Pierre Astolfi
readProcess cmd [opt1,opt2] seems to execute the following: $ cmd "opt1" "opt2"
That is usually fine, but I'm using an external program that doesn't understand the quotes, so I need to execute instead: $ cmd opt1 opt2
How should I do that?
I think your analysis is wrong. I don't know what to suggest, though if you follow up you probably should mention what platform you're running on. Maybe you could devise a simple test program that illustrates the problem? Donn

I've found my mistake: I was calling readProcess cmd ["-p -t"] instead
of readProcess cmd ["-p","-t"]
Not sure what are the semantics of quotation in this case, though. And
I'm pretty sure my analysis is wrong because of that :)
--
Cp
On Thu, Aug 11, 2011 at 16:05, Donn Cave
Quoth Charles-Pierre Astolfi
, readProcess cmd [opt1,opt2] seems to execute the following: $ cmd "opt1" "opt2"
That is usually fine, but I'm using an external program that doesn't understand the quotes, so I need to execute instead: $ cmd opt1 opt2
How should I do that?
I think your analysis is wrong. I don't know what to suggest, though if you follow up you probably should mention what platform you're running on. Maybe you could devise a simple test program that illustrates the problem?
Donn
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Quoth Charles-Pierre Astolfi
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"] Donn

On Thu, Aug 11, 2011 at 11:29, Charles-Pierre Astolfi
I've found my mistake: I was calling readProcess cmd ["-p -t"] instead of readProcess cmd ["-p","-t"]
Not sure what are the semantics of quotation in this case, though. And I'm pretty sure my analysis is wrong because of that :)
It's quite simple: readProcess uses the low level exec*() series of functions under the hood. Quoting is assumed to have already been dealt with; every parameter is a separate String (or (char *) in the C API) and passed literally. Quoting is used at the shell level (and shell-based APIs such as system()) to enable the shell to correctly generate a list of literal (char *) parameters. In general, if an exec-style API takes a list of strings (e.g. C execve(), Haskell readProcess, Perl's multiple-parameter form of system), it's using the exec()-based API and you should pass argument strings exactly as you want the program to see them; if its a single string, it's using a system()-based API and you need to worry about quoting. In this case, the tip-off is that the argument list is a [String] and not simply a String. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Am 11.08.2011 16:45, schrieb Charles-Pierre Astolfi:
Hi -cafe,
I'm using readProcess and I don't know how to handle this issue:
readProcess cmd [opt1,opt2] seems to execute the following:
are you sure that your argument strings do not contain the quotes, possibly by calling "show" on arguments that are already strings. C.
$ cmd "opt1" "opt2"
That is usually fine, but I'm using an external program that doesn't understand the quotes, so I need to execute instead: $ cmd opt1 opt2
How should I do that? -- Cp
participants (4)
-
Brandon Allbery
-
Charles-Pierre Astolfi
-
Christian Maeder
-
Donn Cave