Configuring the current working directory for IEx or Mix?

Hi everybody,

I wanted to know if it’s possible to configure the cwd (current working directory) path of the mix.exs file (which is the root path of the application) for iex.
Let me precise that I don’t want to change the defaults (i.e. move the mix.exs file elsewehre).
But I’m in a situation where I’m invoking mix commands from a directory that it’s not the project root.

For the details, I’m using VS Code tasks shortcuts to run mix commands where the cwd is the workspace directory of VS Code. So the mix commands fail because of not being in the same directory of the mix.exs file (error: Could not find a Mix.Project)

So, in other words I want to be able to run mix commands from another directory than the project root and be able to tell mix or iex (in case of iex -S mix) where to look for the mix.exs file.

I learned that IEx is looking for a dot file .iex.exs (in the cwd or in home) which it runs before starting the IEx session.

So I wonder if there is something equivalent for mix commands (where I can into the project root path) ?
Or if there is a way to define some kind of options in .iex.exs to define the path where mix should look for and then running iex -S mix?

I currently have found a workaround by either by cding before running the mix command (like cd project_dir && mix test) or by defining in VS Code the cwd of the task to run.
But I wanted to know if it’s possible to configure that inside the elixir project.

Thank you.

The working directory is inherited from the parent process.

Though as far as I remember VScode tasks can set the working directory of the task in options.cwd of the task.

1 Like

Yes indeed this is what I’m using at the end.
But I wanted to ask after I learned about .iex.exs file where I put common aliases and imports I use in a session (e.g. Ecto.Query when working with Phoenix).
It’s not a big deal anyway…