Running detached mix task, redirecting strout and stderr to file

I have a mix tasks that processes some data and continuously outputs results to stdout (using IO.puts, IO.write, etc).

To execute the task on server, I would like to run detached process with given mix task, redirecting all output to some file, however I am unable to make it work…

I tried running it with

mix some_task some_arg > my_file.txt &

This executes command in the background, also redirecting the output to given file, but only UNTIL I input some text to the shell, in which case command is stopped (not killed)

I also tried running it with

elixir --detached -S mix some_task some_args > my_file.txt

In this case, output is not redirected to given file (only empty file is created).

Does anyone have any suggestions on how to achieve this?

System: Ubuntu 12.04
shell: bash

What seems to work is piping empty string to stdin of mix command, then subsequent input in terminal does not affect mix execution, e.g.

echo "" | mix some_task some_arg > my_file.txt &


This is incredibly incredibly annoying and unexpected. Does anyone have any ideas on this?

This still doesn’t work.

sudo -Hu pleroma MIX_ENV=dev elixir --erl “-detached” -S mix phx.server > somefile 2>&1