Nicd

Nicd

Port.open EACCES on Windows

I’m using Port.open to execute some npm tools. This works fine on macOS and Linux but fails on Windows with the following reason:

* (ErlangError) erlang error: :eacces
    erlang.erl:2080: :erlang.open_port({:spawn_executable, "/path/to/node_modules/.bin/concisecss.cmd"}, [:exit_status, :stderr_to_stdout, {:args, ["compile"]}, {:line, 1024}])

I can execute concisecss.cmd normally by opening it with Explorer, and I have checked that I have execute permission for it (this happens for every npm program, concise is here just as an example). Is it because it is a bat script? How should I run it on Windows?

Marked As Solved

Nicd

Nicd

Answering myself here with the solution. The problem was that cmd scripts can’t be spawned as executables on Windows, so I had to use cmd.exe. I looked at the :os.cmd sources to see how Erlang does it and found the winning combination.

In the end, the answer was to use cmd.exe /c foo.cmd, but with a Windows-specific flag :hide to the Port opening call. That hides the opened cmd window and sends stdout correctly. Without the flag, the cmd window flashes on the screen and stdout never arrives back to BEAM.

Here is the solution used in the end:

Port.open({:spawn_executable, "c:/windows/system32/cmd.exe"}, [:exit_status, :stderr_to_stdout, :hide, line: 1024, args: ["/c", "c:/path/to/node_modules/.bin/concisecss.cmd"]])

Also Liked

Nicd

Nicd

Yeah, I only found it by looking at how :os.cmd was implemented in the Erlang source. Later on I discovered it’s documented in the Erlang docs as:

When running on Windows, suppresses creation of a new console window when spawning the port program. (This option has no effect on other platforms.)

NobbZ

NobbZ

I can’t try it, but I think, you have to try to spawn it throuch cmd.exe or powershell.exe or whatever interpreter you need. Windows does not know about a concept similar to UNIX’ shebang, but has only some crippled system do determine such stuff by looking at the files ending. But this behaviour isn’t available for tools outside of windows “core” without hooping some loops.

NobbZ

NobbZ

Google says that cmd /c foo.cmd should run foo.cmd without spawning a new window.

Buf as far as I can remember from my erlang things I did, you will loose the access to the spawned programs stdin and -out, which is probably the mainreason for using a Port

Where Next?

Popular in Questions Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

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...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
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
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement