iex "find and execute the given script"

2,932 views
Skip to first unread message

Scott Thompson

unread,
Oct 27, 2015, 6:17:17 PM10/27/15
to elixir-lang-talk
I have written a Elixir script (and by script, I mean a file of Elixir code with the ".exs" extension).

When I look at the command definition for iex I see:

Usage: iex [options] [.exs file] [data]


 
-v                Prints version
 
-e "command"      Evaluates the given command (*)
 
-r "file"         Requires the given files/patterns (*)
 
-S "script"       Finds and executes the given script

When I try to execute my script with iex -S "monitoring.exs" I get

λ <509>$ iex -S "monitoring.exs"
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]


-S : Could not find executable monitoring.exs


OK... I'll bite.  What kind of scripts is "iex -S" supposed to be used with?

Alexei Sholik

unread,
Oct 27, 2015, 6:20:06 PM10/27/15
to elixir-l...@googlegroups.com
It searches for scripts in your PATH. It's useful when running a mix command in IEx:

iex -S mix run

For your own scripts, just pass one as an argument to iex:

iex myscript.exs

Or, if you want to evaluate a few of them, use the -r flag:

iex -r scrip1.exs -r script2.exs

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/63478373-55bf-45b8-91ea-0e54d3548407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Valim

unread,
Oct 27, 2015, 6:21:50 PM10/27/15
to elixir-l...@googlegroups.com
-S is meant to be used to run scripts in your $PATH. If you have the local path, it would be "iex path/to/file".
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/63478373-55bf-45b8-91ea-0e54d3548407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--


José Valim
Skype: jv.ptec
Founder and Director of R&D

Alexei Sholik

unread,
Oct 27, 2015, 6:22:19 PM10/27/15
to elixir-l...@googlegroups.com
And just for the sake of completeness, let me add that when passing the script path as an argument, any additional arguments will be put in System.argv:

# myscript.exs
IO.inspect System.argv

$ iex myscript.exs 1 2 3
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

["1", "2", "3"]
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>

Reply all
Reply to author
Forward
0 new messages