Prompt for input in using the grunt-shell plugin

2019-07-06 00:51发布

问题:

I have a script I am trying to run with grunt using the grunt-shell plugin. This script prompts for input using read -p "enter foo" bar. When I run it, I get a cursor that correctly takes my input, but I don't see "enter foo".

I tried modifying the grunt-shell config to dump err, stderr, and stdout to the console, but they all come out empty once the command completes. The man page for read says about the -p flag "The prompt is displayed only if input is coming from a terminal.", which seems like it may be my issue since node is calling the prompt, but the read command is executing in my terminal, and I am entering input in a terminal, so why wouldn't that work?

So, my question is, is there any way to prompt for user input from the grunt-shell plugin?

Also, as a P.S., yes i know it would be very easy to just echo the prompt and deal with the input being below it, but dammit it's the principle of the thing.

回答1:

I redirected my code back to /dev/tty. Ran it as bash -c run.sh </dev/tty