Functions pending for IO.gets?

For example, if I would like to automate user authorization hex. 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 we expect to work for this

+3


source to share


1 answer


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 can use

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

      

+4


source







All Articles