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:
- the console always appears.
Questions
So this leaves me to the following questions:
- How do I prevent the console from showing?
- Does
demo.batinclude 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 ? - 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
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
-
Follow instructions to create the project from the question above (you may need to enable server options in
config/prod.exs) -
Go to
demo_umbrella\_build\prod\rel\demo\binwhere the newly createddemo.batfile is -
Create a file called
invisible.vbsand add in the following content:
CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False
- Create a Windows shortcut, that looks like this:
The value on the Target field is:
%windir%\system32\wscript.exe invisible.vbs "demo.bat start"
- 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
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
: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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










