# Julia Slurm Cluster Module Command Not Working

**URL:** <https://discourse.julialang.org/t/julia-slurm-cluster-module-command-not-working/113600>\
**Category:** General Usage\
**Tags:** hpc, run, slurm\
**Created:** [April 29, 2024, 4:02am UTC](https://discourse.julialang.org/t/julia-slurm-cluster-module-command-not-working/113600 "2024-04-29T04:02:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [April 30, 2024, 6:37am UTC](https://discourse.julialang.org/t/julia-slurm-cluster-module-command-not-working/113600/5 "2024-04-30T06:37:33Z")

</div>

Thanks for the follow-up information! Despite my unfocused blanket questions 😅 I think we found the issue.

> [@TI36XPro](#):
>
> For example if on the login node I start the Julia REPL and try to do `run(`module list`)` then I get the error. But if I switch to shell mode (`;` in the REPL) then it executes fine.

I just checked on our cluster (we also use Slurm + Lmod) and get the same behavior. The issue seems to be what you already mentioned in the original post:

> [@TI36XPro](#):
>
> If it matters, I read that the module command is a shell function (not sure what that means).

I found similar descriptions [here](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/8) and on [StackOverflow](https://stackoverflow.com/questions/36484596/julia-spawn-source-leads-to-no-such-file-or-directory) explaining the problem and the corresponding part of the [docs](https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs):

> - The command is never run with a shell. Instead, Julia parses the command syntax directly, appropriately interpolating variables and splitting on words as the shell would, respecting shell quoting syntax. The command is run as `julia`’s immediate child process, using `fork` and `exec` calls.

* * *

Short summary:

The _shell_, e.g. `bash` or `zsh`, is a program (executable file/script somewhere on the system) that usually runs when you open a terminal and is used to run all kinds of other programs. Running _commands_ in the shell will either look for another executable file in the system’s path variable(s) and run that _or_ if the command is “built-into” the shell (or defined as a function in some shell script), run that. `module` seems to be the latter.

Since Julia doesn’t run commands in a shell if we use `run(cmd)`, only actual executables in the path will be found. This explains also why `run(`/usr/bin/bash -c module list`)` worked (we first run the shell and then have the `module` shell function available again. Similarly, using the shell mode with `;` will use a shell as well, so that also works.

Here’s a way to tell what is built-in and what is not (the `which` command looks for the executable file that corresponds of the command)  
_EDIT: That’s not quite correct, please check the next reply by @sijo for an important clarification!_

- `which ls` will print something like `/usr/bin/ls`
- `which which` → `/usr/bin/which`
- but `which source` will give `which: no source in (..long list of paths to look into..)`, the `source` command loads shell code from a file
- and similarly `which module` also fails, which indicates that `module` is indeed not a executable file somewhere on the system, but only works within a shell

* * *

> [@TI36XPro](#):
>
> But then I get the error

This is an issue with command parsing. As far as I understand, since `()` can be used in interpolation, e.g. like this:

```julia-repl
julia> a = "hello"
"hello"

julia> cmd = `echo $(a)`
`echo hello`

```

we have to “[qoute](https://docs.julialang.org/en/v1/manual/running-external-programs/#Quoting)” the parentheses if they should appear in the final command.

But `module("list")` from the link you mentioned looks like a call to a Python function and it wouldn’t work in a shell most likely. The syntax for invoking a command with arguments is usually using spaces instead of parentheses, as in `echo hello` (not `echo(hello)`).

---

_[View the full topic](https://discourse.julialang.org/t/julia-slurm-cluster-module-command-not-working/113600)._
