Here are the list of task I would like to automate and capture the output into a text file using Python 3:
- Run the executable
auth_bin - Asks for entering password
- After entering the password from keyboard, it gives an output on the terminal
- Asks for choosing a number
- Generates a file on disk
I can automate inputing my password and the choice number with the following code, but cannot capture the output in step#3.
import subprocess from getpass import getpass choice_num = "5" mypass = getpass('Enter your password: ') subprocess.run(auth_binary, input="\n".join([mypass, choice_num]), text=True) How can I capture screen output into a text file?
BTW, I can give two inputs (step# 2 and 4) from the keyboard and save the screen output from my Mac terminal this way:
auth_bin 2>&1 | tee output.txt