How to add Line break to IO.stream() in terminal showing

Hi friends, I have a block code like this; for example if my user goes to a wrong directory and call this function he/she gets errors.

  def deps() do
    [{:get, "deps.get"}, {:compile, "deps.compile"}]
    |> Enum.map(fn {operation, command} ->
      {stream, status} = System.cmd("mix", [command], into: IO.stream())
      %{operation: operation, output: stream, status: status}
    end)
  end

The error my user gets is like this:

** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file
                                                                                                           ** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file

but I need to print it like this:

** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file
** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file

Each line should have something like /n to make the lines break.

Thank you

You are running that code in IEx session?

Yes, I need to show it better in IEx session in my terminal
Thank you

Maybe try:
{stream, status} = System.cmd("mix", [command], into: IO.stream(), stderr_to_stdout: true)

1 Like

Thank you, it solved my problem and works for me. But I have a question, it changes anything or just capture each line by line?

I found it in

  • :stderr_to_stdout - redirects stderr to stdout when true

But I can not understand what it is actually.