Hey! I’m trying to write my first Roc program which is a CLI tool. It needs to run a command and read its output. I’m defining the command as:
Cmd.new "git"
|> Cmd.args ["log", "--pretty=format:\"%H %aI\""]
And running it with Task.await (Cmd.output gitLogCmd)
, getting the actual Output and turning it into a string with Str.fromUtf8
. It works, but my problem here is that each line from the output is enclosed in double quotes:
"4df174c59ec48c135a5e7369d3deeca56497056a 2024-04-03T10:11:49+02:00"
"b620b1a55428862e44cc5cf06703de043bd46ed1 2024-04-03T10:11:11+02:00"
Is that expected? Also the definition of the Output type was quite hard to find, it doesn’t seem to appear in the docs?
Hi @Sylvain Brunerie,
Can you share your full code?
Also the definition of the Output type was quite hard to find, it doesn’t seem to appear in the docs?
I'll make an issue for that :)
Oh so it looks like it’s just about the argument to git log
. Cmd.args ["log", "--pretty=format:\"%H %aI\""]
is actually adding the surrounding quotes. So it works perfectly with Cmd.args ["log", "--pretty=format:%H %aI"]
but I can’t run the command this way in the shell. That means I have to change my command from the shell to Roc. Feels weird but maybe it makes sense.
@Anton this is reproducible outside the context of Roc via:
git log --pretty=format:"\"%H %aI\""
It seems that in @Sylvain Brunerie's case, \"
is interpreted by Roc with an equivalent result (which doesn't seem intuitive as an interpretation; the first \"
seems to be interpreted differently from the second instance, e.g., as if it's a closing and opening quotation marks), whilst the desired output is probably something like:
git log --pretty=format:"%H %aI"
This might be relevant: https://doc.rust-lang.org/std/process/struct.Command.html#method.args
Note that the arguments are not passed through a shell, but given literally to the program. This means that shell syntax like quotes, escaped characters, word splitting, glob patterns, variable substitution, etc. have no effect.
That’s the function called by the underlying basic-cli platform, so I guess the behaviour is expected. For now, I find it very confusing, but maybe it’s for the best, and there should just be a similar warning in the platform docs.
and there should just be a similar warning in the platform docs.
I'll do that :)
Last updated: Jul 05 2025 at 12:14 UTC