0

I have a fabric task that looks like this:

@task
def test():
    with settings(prompts={'This is a test.': 'q', 'question?':'answer'}):
        run("python test.py")

my test.py script looks like this:

import subprocess, os
subprocess.call(['less', '-e', os.path.abspath('test.txt')])
response = raw_input("A question?")
print("response is [{0}]".format(response))

And test.txt contains:

This is a test.

If I run this, and I add a few prints in fabric to see what's happening, indeed when reading the file fabric finds the text, enters q. It then stops on raw_input, sends the response. But raw_input gets "" as an answer instead of response!!

If I remove 'question?':'answer' from my prompts dict, and enter the answer manually, again, it is somehow swallowed...

However if I remove 'This is a test.': 'q' and exit the less command manually, both manual or automatic response for the raw_input work again.

How can I exit less without my subsequent answers being swallowed? Of course, I simplified a real life scenario where I can't change these files...

seven-phases-max
  • 11,765
  • 1
  • 45
  • 57

1 Answers1

2

this must has to do with terminal and interactive mode + less behavior about that.

Add pty=False to your run(..) arguments and this should solve your situation.

gst
  • 431
  • 1
  • 4
  • 16
  • 1
    also, in the docs http://docs.fabfile.org/en/1.14/usage/interactivity.html For situations requiring the pty behavior turned off, the --no-pty command-line argument and always_use_pty env var may be used. – Kevin Eaverquepedo Nov 02 '17 at 22:18