Call shell commands

Does Elm provide any way of sending a command to my shell, or calling it directly?

Is there any way of communicating with my system this way?

I would also love to read the STDOUT, Status, and STDERR, if possible :slight_smile:

Elm out-of-the box is more like a UI-framework bundled with a language so running with node.js is not really a thing (with vanilla Elm)

There are quite a few attempts on solving that (meaning have Elm run in Node) one I could find that seems to be actively maintained is elm-fullstack but that might be more than you want.

Personally I donโ€™t use Elm for backend or scripting stuff and I think the MVU pattern that is so prevalent in Elm does not really handle that well but Iโ€™m sure you can do it.

1 Like

Elm does not really advertise itself as being suitable for this use case, since it is really aimed at the UI.

However, you can run Elm in Node.js using a Platform.worker. You would write a script in JS to handle the command line inputs and STDIN, set up an Elm program, pass the inputs to the Elm program through its init flags or a port, take output from the Elm program through ports, and then use those outputs to do something useful on the system such as writing to files or STDOUT and so on.

Here is an example of such a script. This one I wrote to drive a code generator that turns AWS service specs into Elm stubs to call those services. It might help you to understand how to work with Elm in this style:

You should also take a look at this: elm-posix 1.1.0


Thanks for all the insight. I assume, I just Interpret it like that, while I am not entirely sure, if someone might have inferred, that I am nessecarly speaking about the Node shell.

I would love to bypass JavaScript and just call binaries, like my systems package manager.

Pacman, in order to create a package manager UI for it.

P.S: I had already seen elm-posix and it looks kinda useful for thia task. Although, I am not sure if and how I could get response back.

I was more looking for something like System โ€” Elixir v1.13.4

Elm-fullstack looks interesting as well.

Elm is a pure programming language, so making side effects like that is tricky. Elm runtime helps us with general side effects used in web development, like making an http request. But itโ€™s not a general purpose language, so any other side effects outside of the web development context are not build into itโ€™s runtime.

And no ffi (foreign function interface) is provided either. So there is no native way to bypass it and make an OS call or any side effect that are not managed by the runtime.

These projects presented on the other replies kinda extends Elm to enable/experiment other use cases outside web development world. But keep in mind that the language was not originally designed to be used outside of webapps development, so the experience might not be optimal.

1 Like

I decided to do the system level stuff in its own app, probably in the fish language.

I figured, its probably safe and sane, to use specific toolsets to solve their specific use cases.

I can then export/produce the necessary document files and read them with elm-pages

Elm-pages with its DataSource seems like a superb way to do things like that!


1 Like

There is no synchronous ffi as such, but there are ports. Ports are how you interface Elm to side effects outside of its runtime.


Yeah, but ports are complicated to setup, like on purpose.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.