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’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
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
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 the...
New
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
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
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









