Using set input for stdin based on output from stdout with python subprocess -
i install software automatically python using subprocess.popen. during installation, software outputs information , asks user couple of questions (e.g., whether agree software license or install software). these questions, answer them automatically pythong code. however, tried several ways none of them worked me. idea of how make it? expected pseudo code follows (definitely, code not work).
p = subprocess.popen(['myprogram'], stdout=subprocess.pipe, stdin=subprocess.pipe, stderr=subprocess.stdout)) while (p.poll() == none): line = p.stdout.readline() if not line: break else: print line.strip() if line == 'do accept license agreement (yes/no)': p.stdin.write('yes/n') elif line == 'do want install software (yes/no)': p.stdin.write('yes/n')
thanks thomas fenz. pypi.python.org/pypi/pexpect excellent in case. in previous comment, said didn't work because made mistake in pattern specification. in particular, used p.expect('do accept license agreement? (yes/no)'). question mark in case mistake. meta character, pattern not matched , hence timeout happened.
Comments
Post a Comment