1

I am currently working with a script that defines expected configuration values, reads a configuration file for values, and finally prompts for any values expected but not specified in the configuration file.

Example expected configuration items:

username password command directories

Example configuration file:

username:bob
command:"rm -rf / && echo bwahahahahaha"

Example prompt:

password? userinput  
directories? userinput

The crux of the issue is that not all configuration items are known prior to runtime, and can be piped in from a text file or output of another program, but may still leave a gap in configuration items (triggering a prompt).

[host]$ parametergeneratingscript.rb | paramaterreceivingscript.rb        # still needs to prompt for password  

Using IO#tty? in I am able to detect the piped input and appropriately read from STDIN, but this is walking all over the user prompts (which also come from STDIN). I'm comfortable changing around the config / prompt scheme, but before I run off and nuke it, was wondering if there was a graceful way to "toggle" the source of STDIN between tty and piped input?

1 Answer 1

2

Have you tried STDIN.reopen('/dev/tty')? I believe this will reopen STDIN to read from the keyboard instead of from the pipe.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually ended up designing my way around the problem - piped input req was dropped, so OptionParser / Highline became the best solution, though it doesn't answer the initial question. Thanks for the input, and will have to give this suggestion a shot when I get a few moments to test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.