Rich_Morin

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

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).

Where Next?

Popular in Questions Top

JorisKok
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
quazar
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
Kagamiiiii
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mgjohns61585
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
qwerescape
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Mooodi
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
vrod
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 Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
pmjoe
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
yawaramin
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
New
Jim
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
lk-geimfari
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
alice
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
siddhant3030
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

We're in Beta

About us Mission Statement