Why can't I get IEx.pry to work on Windows?

巧了我就是萌 提交于 2020-01-05 07:28:56

问题


I am trying to make IEx.pry work with the following code example:

require IEx;

defmodule Example do
  def double_sum(x, y) do
    IEx.pry
    hard_work(x, y)
  end

end

Example.double_sum(1, 2)

When I run it I get the following error:

Cannot pry #PID<0.106.0> at lib/example.ex:5. Is an IEx shell running? If you are Windows, you may need to start IEx with the --werl flag.

In response I launched iex with --werl and it opened the erlang shell.

In the erlang shell I tried to change directories so that I can launch the file. I did this by typing:

cd(c:/Users/william/Desktop/example)

I received the following error:

(SyntaxError) iex:1: keyword argument must be followed by space after: c:

回答1:


Assuming the module code is located in "c:/Users/william/Desktop/example.ex", one might enter the iex and force a compilation from there:

iex> c "c:/Users/william/Desktop/example.ex"

Request to pry #PID<0.89.0> at /tmp/a.ex:5

    defmodule Example do
      def double_sum(x, y) do
        IEx.pry
        x + y
      end

Allow? [Yn] y

Interactive Elixir (1.5.0-dev) - press Ctrl+C to exit (type h() ENTER for help)
pry(1)> 

Once "y" is pressed, you have pry prompt entered.


Another option would be to use mix to manage source code, even such simple source code. mix new will create new package. To enable IEx.pry support in mix one should run mix tasks prepended with iex -S:

iex -S mix # for just iex in mix environment

or:

iex -S mix phoenix.server

to enable IEx.pry support in phoenix application.

  • IEx docs;
  • Intro to mix.

Sidenote: semicolon after require IEx is redundant and is a code smell.



来源:https://stackoverflow.com/questions/41540289/why-cant-i-get-iex-pry-to-work-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!