Expect-like functionality to IO.gets?

114 views Asked by At

For example, if I wanted to automate authorizing a hex user. Something like

mix hex.user auth
#!/usr/bin/expect -f

expect "Username: "
send -- "$HEX_USERNAME\r"
expect "Password: "
send -- "$HEX_PASSWORD\r"

mix hex.user auth asks for Username: and Password: but I don't think expect works for this

1

There are 1 answers

0
Michelle Tilley On

Given the following script:

u = IO.gets("Username: ") |> String.strip
p = IO.gets("Password: ") |> String.strip

IO.puts ""
IO.puts "#{u} - #{p}"

You can pass input like this:

$ export HEX_USERNAME="hexuser"
$ export HEX_PASSWORD="hexpass"
$ echo "$HEX_USERNAME\n$HEX_PASSWORD" | elixir test.exs
Username: Password:
hexuser - hexpass

So, you could use

echo "$HEX_USERNAME\n$HEX_PASSWORD" | mix hex.user auth