Search code examples
windowselixirphoenix-frameworkrelease

How to start phoenix application without showing terminal in Windows 11


Background

I am creating a simple Phoenix umbrella application to run on a client's Windows 11 machine and my objective is to have something like an .exe file for running said application.

Code

I am creating the application and releasing it using Elixir's normal release procedure, using the commands:

mix phx.new demo --umbrella --no-ecto --no-dashboard --no-gettext --no-mailer
cd demo_umbrella
mix deps.get

# set MIX_ENV=prod before doing this last step!
mix release demo

For those of you curious, this is the releases function I am using inside my mix.exs:

  defp releases,
    do: [
      demo: [
        applications: [
          demo_web: :permanent,
          runtime_tools: :permanent
        ],
        include_executables_for: [:windows]
      ]
    ]

Now, this basic setup will create a .bat file: _build\prod\rel\demo\bin\demo.bat that I can start and stop via the following commands: _build\prod\rel\demo\bin\demo {start | stop}.

Problems & Research

Users that know programming can simply open a terminal in Windows, type _build\prod\rel\demo\bin\demo start and the application will launch (accessible via localhost:4000).

But users normally don't have such knowledge. So I want something as close to an .exe file as possible.

I have tried using Bakeware:

And its spiritual successor, Burrito:

Unfortunately, both fail to work for Windows 11. This leads me to try the shortcut approach. Here I create Windows shortcut to demo.bat and I specify in the target path the commands:

Which in this case will be %windir%\system32\cmd.exe /c start "" "%CD%\demo.bat" start

Now, all is fine and dandy, but there is a problem:

  1. the console always appears.

Questions

So this leaves me to the following questions:

  1. How do I prevent the console from showing?
  2. Does demo.bat include the erlang VM and the elixir version needed to run the application? Or do I need to have those installed in the client's machine ?
  3. I am under the impression that Elixir releases are supposed to include everything needed (https://elixir-lang.org/getting-started/mix-otp/config-and-releases.html):

A release is a self-contained directory that consists of your application code, all of its dependencies, plus the whole Erlang Virtual Machine (VM) and runtime. Once a release is assembled, it can be packaged and deployed to a target as long as the target runs on the same operating system (OS) distribution and version as the machine that assembled the release.

, but in case this bat file does not include everything, how do I fix this?


Solution

  • 1.) Prevent the console from showing: https://superuser.com/questions/140047/how-to-run-a-batch-file-without-launching-a-command-window

    and this:

    https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way

    2.) No I don't think it will. I think you will need to install the Erlang VM on the target machine. I'm speaking from a bit of experience here (although it's been literally years since I tried to deploy an Elixir app on someone else's Windows box).

    3.) Bear in mind that most advice about deploying Elixir apps simply doesn't hold with Elixir on Windows. I used to try to help @bitwalker to get releases going on Windows and between the two of us we never could get a satisfactory approach.

    If there's some way you could run your app under WSL that'd probably remove some of the difficulties.

    4.) I know you didn't ask but having the Phoenix server start on a Windows 11 box on bootup will likely require you to monkey with Windows Services. This is also not a trivial thing.