kokolegorille

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

NobbZ

The quotes are a shell thing, just leave them off and just use "circle 100 100 100 1".

Also Liked

kokolegorille

kokolegorille

Oh my… it is now working fine :slight_smile:

Where Next?

Popular in Questions Top

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
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
dokuzbir
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
nsuchy
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
script
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
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
shahryarjb
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
LegitStack
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
ovidiubadita
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
WestKeys
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 Top

yurko
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
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
axelson
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...
239 45766 226
New
ycv005
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
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
ovidiubadita
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

We're in Beta

About us Mission Statement