I want to use python to send a command to a terminal and I am doing it with:
subprocess.call('ask util generate-lwa-tokens')
Normally in the terminal it will ask me to input my client ID next. How can I send the client ID to the subprocess?
I want to use python to send a command to a terminal and I am doing it with:
subprocess.call('ask util generate-lwa-tokens')
Normally in the terminal it will ask me to input my client ID next. How can I send the client ID to the subprocess?
Try the subprocess manual. You have options with subprocess to work with stdin, stdout, and stderr of the process you're calling.
from subprocess import Popen, PIPE, STDOUT
p = Popen(['ask', 'util', 'generate-lwa-tokens'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, universal_newlines=True)
# Storing the values that should be passed
values = ["client_id", "client_secret"]
# Interacting with the shell
output, err = p.communicate(input=f'{values[0]}\n{values[1]}\n')
# Displaying outputs
print(output)
Try this and comment if there are any errors.