10

According to this StackOverflow thread about piping input, running echo "yes" | command should pass yes to the first prompt of a command. However, echo "yes" | python manage.py flush produces the error

EOFError: EOF when reading a line.
Community
  • 1
  • 1
Bentley4
  • 10,678
  • 25
  • 83
  • 134

4 Answers4

35

I suspect that manage.py is requesting more than one line of input. Is there a reason you can't use

 python manage.py flush --no-input

as documented?

msw
  • 42,753
  • 9
  • 87
  • 112
  • This doesn't directly answer my question but it's the solution I'm going to use. : ) Thank you! – Bentley4 May 02 '13 at 19:41
  • You got two answers that directly spoke to the error you gave us: it wants more input than you gave it. Failing further information from you, that's as good as anyone can guess. – msw May 02 '13 at 20:32
  • The other users just assumed I wanted yes for both prompts which I didn't ask(except zebediah49). I only asked to automate input on the first prompt. But I could have been more clear and explicit that I didn't want any automation for the second prompt I guess. Nevertheless I'm grateful for your input. – Bentley4 May 02 '13 at 21:35
13

Reading your comments, it appears you want to get the first one automated, and then have it ask for the rest.

You may or may not have learned this from that link:

The manage script asks for input on stdin. Echo passes its output to its stdout, then closes.

You want to pass the echoed 'yes' to stdout, followed by reading from keyboard.

cat <(echo "yes") - | python manage.py

Will concatenate (output from one, then the next) the content of echo yes (pretending it's a file), followed by the content of stdin. As a result, you get the first automated answer, followed by a prompt for the rest.

Note that you can even do this more than once:

cat <(echo "yes") - <(echo "no") -

Will output "yes", followed by whatever you type in, until you end with ctl-d, followed by "no", followed by whatever you put in, until you end with ctl-d.

zebediah49
  • 7,467
  • 1
  • 33
  • 50
7

This will work, assuming that the yes command is installed (it should be) : yes yes | python manage.py flush

But as mentionned : python manage.py flush --no-input is probably better.

Julien Grenier
  • 3,364
  • 2
  • 30
  • 43
  • 2
    +1 presuming that an infinite series of "yes" doesn't eat his CMS >. – msw May 02 '13 at 20:34
  • I know about the yes command, but I can't use it here since I don't want to answer yes to the second command. But I could have provided this info so sorry about that. – Bentley4 May 02 '13 at 21:22
1

Most likely "python manage.py flush" expects additional input after reading "yes", which it doesn't get, because "echo "yes"" finishes and its output file is closed.

You need to figure out what else "python manage.py flush" expects and provide that on its input.

spbnick
  • 5,025
  • 1
  • 17
  • 22
  • The command outputs 2 yes/no prompts. I didn't know that if multiple prompts are given in a command, the command failed if only 1 input to a prompt is automated. Seemed logical that it would input that one prompt and continue to ask the second one. `yes` or `no` is the only thing that is prompted for btw. – Bentley4 May 02 '13 at 19:40