# Call shell commands

**URL:** <https://discourse.elm-lang.org/t/call-shell-commands/8625>\
**Category:** Learn\
**Created:** [August 30, 2022, 8:42am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625 "2022-08-30T08:42:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShalokShalom](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/shalokshalom/32/2203_2.png) [@ShalokShalom](https://discourse.elm-lang.org/u/ShalokShalom)\
**Post date:** [August 30, 2022, 8:42am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/1 "2022-08-30T08:42:20Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Carsten\_Konig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/carsten_konig/32/4063_2.png) [@Carsten\_Konig](https://discourse.elm-lang.org/u/Carsten_Konig)\
**Post date:** [August 30, 2022, 8:49am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/2 "2022-08-30T08:49:56Z")

</div>

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](https://github.com/elm-fullstack/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.

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [August 30, 2022, 9:32am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/3 "2022-08-30T09:32:10Z")

</div>

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:

> <https://github.com/the-sett/elm-aws-codegen/blob/master/src/index.js>

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [August 30, 2022, 9:32am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/4 "2022-08-30T09:32:37Z")

</div>

You should also take a look at this: [elm-posix 1.1.0](https://package.elm-lang.org/packages/albertdahlin/elm-posix/latest/)

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/shalokshalom/32/2203_2.png) [@ShalokShalom](https://discourse.elm-lang.org/u/ShalokShalom)\
**Post date:** [August 30, 2022, 7:56pm UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/5 "2022-08-30T19:56:53Z")

</div>

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.  
Thanks

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](https://hexdocs.pm/elixir/System.html#cmd/3)

Elm-fullstack looks interesting as well.

---

<div class="post-metadata">

**Author:** ![marciofrayze](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/marciofrayze/32/3494_2.png) [@marciofrayze](https://discourse.elm-lang.org/u/marciofrayze)\
**Post date:** [August 30, 2022, 8:28pm UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/6 "2022-08-30T20:28:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/shalokshalom/32/2203_2.png) [@ShalokShalom](https://discourse.elm-lang.org/u/ShalokShalom)\
**Post date:** [August 30, 2022, 8:39pm UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/7 "2022-08-30T20:39:07Z")

</div>

I decided to do the system level stuff in its own app, probably in the [fish](https://fishshell.com/docs/current/language.html) 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](https://elm-pages.com/)

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

Thanks!

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [August 31, 2022, 8:53am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/8 "2022-08-31T08:53:16Z")

</div>

> [@marciofrayze](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/shalokshalom/32/2203_2.png) [@ShalokShalom](https://discourse.elm-lang.org/u/ShalokShalom)\
**Post date:** [August 31, 2022, 11:21am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/9 "2022-08-31T11:21:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [September 10, 2022, 11:22am UTC](https://discourse.elm-lang.org/t/call-shell-commands/8625/10 "2022-09-10T11:22:25Z")

</div>

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