Fl4m3Ph03n1x

Fl4m3Ph03n1x

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?

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Answer

Following an SO post:

I was able to create a shortcut that achieves my purposes, using VB as well. At the very least, this will launch the application. Closing may be another concern and I still need to test this with Elixir Desktop. However, these are questions that likely deserve their own posts, so if I find the need, I will leave them for later.

Instructions

  1. Follow instructions to create the project from the question above (you may need to enable server options in config/prod.exs)

  2. Go to demo_umbrella\_build\prod\rel\demo\bin where the newly created demo.bat file is

  3. Create a file called invisible.vbs and add in the following content:

CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False
  1. Create a Windows shortcut, that looks like this:

The value on the Target field is:

%windir%\system32\wscript.exe invisible.vbs "demo.bat start"

  1. Upon clicking the shortcut, the application will be launched behind the scenes and you will be able to check it under localhost:4000.

This shortcut will run the files from the folder it is in, so you can safely move things around provided you always keep it in the same folder the rest of the files are.

Being a shortcut, it also means you can change the icon to anything you want.

Also Liked

LostKobrakai

LostKobrakai

Release inclde everything needed for you to be able to run it on the target system. You can do that using the .bat. It’s however not meant to build a single/standalone executable (.exe / binaries on other os’s).

Yes(ish). It includes everything so an OTP/Elixir installation is not necessary. There might be other lower level dependencies left though, which are still required, but often expected to exist on target systems.

What do you think it doesn’t include, that would be needed to run the release?

LostKobrakai

LostKobrakai

:wx will be in the release (if you setup the dependency in mix.exs). I don’t think wxwidgets specifically are included in the release. How external (native) dependencies are handled always depends on the application integrating with that dependency. That’s nothing elixir (or OTP for the matter) could affect in a general application independant way.

Also nothing will be “in the bat” specifically. The release only works as a whole with all the files within it. The bat is only the entry point.

While cross compilation is not necessarily an easy topic it is not impossible to build for windows from linux.

LostKobrakai

LostKobrakai

If you stick to the default release root then everything within _build/MIX_ENV/rel/YOUR_APP is “the release”. You need everything in there in the same places relative to each other. Or said otherwise. Don’t attempt to move pieces within that folder. You can add the :tar release step in mix.exs to get a .tar archive of the same contents, though as a single archive file.

I didn’t quickly find any documentation on :wx if you need to install wxwidgets on a target machines as well, or if it’s only a build time dependency. If you have a spare machine you could probably test it though.

I wasn’t arguing that it’s preferable, but that it’s not impossible. How difficult it would be depends on what all you need to build and actually cross compile.

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127536 1222
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement