I’m working with a project that is doing a command line invocation of some Elixir functions that we also use within our GUI. The CLI starts from a bash shell, passes through at least one sh shell, and ends up invoking exec elixir --eval "$2". The program outputs data with a form like “a: b\nc: d\n”, using IO.puts. The problem is that the newlines don’t show up in the shell output. I just get the newlines replaced by spaces, so “a: b c: d”.
Is there something extraordinary I need to do in Elixir to do this, or is there some relatively simple thing missing in some path of the shell scripts?
In bash for example you can type sh, so you would be in sub-shell. You should see the output before said “crash”. For me it works as expected even with \n character in Elixir string.
Dropping into sh helped. And made me remember that the description of exec is that it replaces the current shell with that command, which is why the exit. The sh test confirmed that even with the eval I am definitely getting my newlines. Into the bowels of the shell scripts I go, looking for answers.
The first level shell was doing "ret = command $options" and by putting the command in back ticks the output was coalesced into a single line of output. The shell was doing this in an attempt to be able to awk the output to detect just the one expected line of output. However in my testing to date I haven’t found any unexpected output that I didn’t add, so I don’t think I need to awk the output and can just call “command $options” and let the output output.