bmitc

bmitc

Erlang "init terminating in do_boot" error when calling Elixir from .NET

Hello! I am working on something where I am trying to pass data between .NET, namely F#, and Elixir through the command line. On Windows, I am getting a strange error that I can’t figure out.

Here is my F# function:

let executeProcess name arguments =
    let startInfo = System.Diagnostics.ProcessStartInfo(
        FileName = name,
        Arguments = arguments,
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true
    )
    use p = new System.Diagnostics.Process(StartInfo = startInfo)
    p.Start() |> printfn "Successfull?: %A"
    p.WaitForExit()
    p.StandardOutput.ReadToEnd()

On Ubuntu, this works without issue (you can try by copy and pasting this into a dotnet fsi session after downloading the latest .NET SDK or you can try it in a Polyglot Notebook in VS Code, which requires no install I believe as it installs F# for you):

$ dotnet fsi

Microsoft (R) F# Interactive version 12.4.0.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> <copy and paste above function>;;
val executeProcess: name: string -> arguments: string -> string

> executeProcess "dotnet" "--version";;
Successfull?: true
val it: string = "7.0.101
"

> executeProcess "elixir" "--version";;
Successfull?: true
val it: string =
  "Erlang/OTP 25 [erts-13.1.4] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]

Elixir 1.14.3 (compiled with Erlang/OTP 25)
"

>

However, on Windows, I get a strange Erlang init error but notice that Elixir works just fine on the command line:

PS > elixir.bat --version
Erlang/OTP 25 [erts-13.0.4] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]

Elixir 1.14.2 (compiled with Erlang/OTP 25)
PS > dotnet fsi

Microsoft (R) F# Interactive version 12.8.0.0 for F# 8.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> <copy and paste above command>;;
val executeProcess: name: string -> arguments: string -> string

> executeProcess "dotnet" "--version";;
Successfull?: true
val it: string = "8.0.100-preview.6.23330.14
"

> executeProcess "elixir.bat" "--version";;
Successfull?: true
val it: string =
  "{"init terminating in do_boot",{undef,[{elixir,start_cli,[],[]},{init,start_em,1,[{file,"init.erl"},{line,1220}]},{init,do_boot,3,[{file,"init.erl"},{line,910}]}]}}
"

This is where I get this weird error of {"init terminating in do_boot",{undef,[{elixir,start_cli,[],[]},{init,start_em,1,[{file,"init.erl"},{line,1220}]},{init,do_boot,3,[{file,"init.erl"},{line,910}]}]}}. Searching and even looking up the line numbers in init.erl, this error seems to be because of Erlang version issues. However, that is not an issue on my machine. Elixir and Erlang via iex and erl work just fine, as does elixir.bat --version from the command line.

There seems to be something in how the .NET process launcher is interacting with the Elixir.bat that one or the other doesn’t like. Does anyone know what’s going on here? Is this an issue with elixir.bat on Windows?

(Note: There is a workaround, and it is to actually make the filename "powershell" with arguments "elixir --version". However, I don’t know why that works and the other doesn’t. The Elixir binaries/scripts are in my path, as are the Erlang binaries.)


Edit: I went ahead and tried this on the latest versions of Elixir 1.15.4 and Erlang/OTP 26. The Erlang "init terminated in do_boot" error seems to have gone away, but nothing is written to standard out when running this code as above. However, if I remove the redirection from standard out and reading, I get the following error in FSI:

> let executeProcess name arguments =
-     let startInfo = System.Diagnostics.ProcessStartInfo(
-         FileName = name,
-         Arguments = arguments
-     )
-     use p = new System.Diagnostics.Process(StartInfo = startInfo)
-     p.Start() |> printfn "Successfull?: %A"
- ;;
val executeProcess: name: string -> arguments: string -> unit

> executeProcess "elixir.bat" "--version";;
Successfull?: true
val it: unit = ()

> Error! Failed to load module 'elixir' because it cannot be found. Make sure that the module name is correct and
that its .beam file is in the code path.

Runtime terminating during boot ({undef,[{init,start_it,1,[{_},{_}]},{init,start_em,1,[{_},{_}]},{init,do_boot,3,[{_},{_}]}]})

Crash dump is being written to: erl_crash.dump...done

First Post!

lud

lud

Did you install elixir from something that requires some environment from your shell, like asdf for instance?

Last Post!

cmo

cmo

https://github.com/erpuno/etf

After setting things up, I loop over this:

// reply ok on startup
    sendOk (encode "0")
    try
        while true do
            inputBufferSize <- stdin.Read(inputBuffer, 0, 4)
            // input buffer should be size 4, which tells us the size of the message
            match inputBufferSize with
            | 4 -> ()
            | 0 ->
                logger.Debug "Port shutdown, exiting"
                cleanup logger connection
                Environment.Exit(int ReturnCode.Ok)
            | size ->
                logger.Error $"Expected 4 bytes, got {size} containing '{Encoding.UTF8.GetString(inputBuffer)}'"
                cleanup logger connection
                Environment.Exit(int ReturnCode.BadMessageSize)
                
            let msgSizeBytes =
                if BitConverter.IsLittleEndian
                then inputBuffer |> Array.take 4 |> Array.rev
                else inputBuffer |> Array.take 4
            let msgSize = BitConverter.ToInt32(msgSizeBytes, 0)
            
            // read the ETF
            inputBufferSize <- stdin.Read(inputBuffer, 0, msgSize)
            
            // decode the ETF
            let term = ETF.Decoder.decodeTerm inputBuffer
            
            match term with
            | Term.Tuple [Term.Binary requestId; msg] ->
                match decodeMessage msg with
                | SomeMessage(arg1, arg2) -> 
                ...

Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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 49266 226
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement