kokolegorille
How to provide quoted parameters to System.cmd
Hello everyone,
I am trying to run image magick convert from Elixir. The command I am trying to replicate is…
$ convert -size 200x200 xc:Black -fill White -draw 'circle 100 100 100 1' -alpha Copy mask.png
Which is working fine in the shell. It generates a new image correctly.
And now I am trying to do this in the BEAM.
def build_mask(size) do
params = [
"-size",
"#{size}x#{size}",
"xc:Black",
"-fill",
"White",
"-draw",
"'circle 100 100 100 1'",
"-alpha",
"Copy",
"mask.png"
]
System.cmd(convert(), params)
end
defp convert() do
case System.cmd("which", ["convert"]) do
{convert_cmd, 0} -> String.trim_trailing(convert_cmd, "\n")
{_, 1} -> ""
end
end
which fails with
convert: non-conforming drawing primitive definition `circle 100 100 100 1' @ error/draw.c/RenderMVGContent/4397.
The problem is in these lines, if I comment them, the command is working.
"-draw",
"'circle 100 100 100 1'",
So my question is how to pass a quoted parameters like this ‘circle 100 100 100 1’.
I have been trying different combination, with escape, double quote and what not.
Does anybody hit the same problem trying to wrap convert command in the BEAM?
Thanks for taking time
Marked As Solved
NobbZ
The quotes are a shell thing, just leave them off and just use "circle 100 100 100 1".
6
Also Liked
kokolegorille
Oh my… it is now working fine 
2
Popular in Questions
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
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, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
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 believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
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
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New







