automatically Interact with script using subprocess in python

Viewed 29

For the life of me I can't get subprocess to communicate/write to the saml2aws script. I want to automate the entire configuration tree, but I can't even get the first step to accept "Browser" as a valid input. What am I missing here? (I've been racking my brain trying to pass "Arrow" keys, I've attempted every iteration I could find on other stack overflow questions, but nada.

Edit: This is a windows machine, so pexpect is out of the question.

saml2aws

CODE:

from subprocees import PIPE, Popen
from shlex import split

p = Popen(split('saml2aws configure'), stdin=PIPE, stdout=PIPE, stderr=PIPE)

#neither of these are selecting Browser at the first menu
p.stdin.write(b"Browser\n")
p.communicate(b"Browser\n")[0]

#the list of commands I want to pass are:
"Browser\n profile\n https://my.url\n \n \n"

#These correspond to the options in saml2aws configure
#1) Browser
#2) Profile Name
#3) URL
#4) Username (Optional)
#5) Password (Optional)
0 Answers
Related