Rich_Morin
Peculiar interaction between System.cmd/2 and "git log"
I just ran into some peculiar behavior when using System.cmd/2 to invoke git log. Can someone tell me what is going on?
When I run git log from the command line, the string “format:” does not appear in the result:
$ git log -1 --pretty="format:%ci" mix.exs
2020-02-03 10:37:31 -0800
$ git log -1 --pretty="%ci" mix.exs
2020-02-03 10:37:31 -0800
However, when I run the command via System.cmd/2, the string “format:” does appear:
$ iex
...
iex(1)> arg_list = ~w(log -1 --pretty="%ci" mix.exs)
["log", "-1", "--pretty=\"%ci\"", "mix.exs"]
iex(2)> System.cmd("git", arg_list)
{"\"2020-02-03 10:37:31 -0800\"\n", 0}
iex(3)> arg_list = ~w(log -1 --pretty="format:%ci" mix.exs)
["log", "-1", "--pretty=\"format:%ci\"", "mix.exs"]
iex(4)> System.cmd("git", arg_list)
{"\"format:2020-02-03 10:37:31 -0800\"\n", 0}
Wazzup?
-r
Most Liked
NobbZ
Assuming you are using a POSIX compliant shell, your second System.cmd/2 call is equivalent to the following on your shell:
git log -1 --pretty='"format:%ci"' mix.exs
You need to omit the doublequotes in elixir (you do not even need them on your shell).
4
Popular in Questions
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
I would like to know what is the best IDE for elixir development?
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New







