How to pass 'yes' to python manage.py flush?

10,194

Solution 1

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.

Solution 2

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?

Solution 3

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.

Solution 4

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.

Share:
10,194
Bentley4
Author by

Bentley4

Profile with mostly old questions where I learned about programming. Thank you SO!

Updated on July 21, 2022

Comments

  • Bentley4
    Bentley4 almost 2 years

    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.
    
  • Bentley4
    Bentley4 about 11 years
    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
    Bentley4 about 11 years
    This doesn't directly answer my question but it's the solution I'm going to use. : ) Thank you!
  • msw
    msw about 11 years
    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
    msw about 11 years
    +1 presuming that an infinite series of "yes" doesn't eat his CMS >.<
  • Bentley4
    Bentley4 about 11 years
    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
    Bentley4 about 11 years
    Thank you, very well explained!
  • Bentley4
    Bentley4 about 11 years
    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.