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

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement