piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 34 forks source link

Documentation on how to handle STDIN? #24

Closed robotex82 closed 7 years ago

robotex82 commented 7 years ago

Hi,

I have a question regarding the input stream. Assume I have a cli program, that first asks for an email address and then asks for a password via STDIN. How can I handle this situation?

I tried something like this, but I am not able to split the input, so it inputs the email address first, and then the password.

TTY::Command.new.run("my_cli_program", "login", in: StringIO.new("username@example.com\r\npassword")).out

Any clues?

Many thanks!

Best regards, Roberto

robotex82 commented 7 years ago

After some experimentation, I solved it like this:

in_stream = StringIO.new
in_stream.puts "username@example.com"
in_stream.puts "password"
in_stream.rewind

TTY::Command.new.run("my_cli_program", "login", in: in_stream).out
robotex82 commented 7 years ago

Added pull request #25

piotrmurach commented 7 years ago

Hi Roberto,

Thanks for using the library.

This gem uses spawn under the covers and hence supports all of its parameters see.