touch my body touch my body - 4 months ago 27x
Python Question

Print password prompt using Python's subprocess

If I run a terminal command from Python using

, how do I print the password prompt?

I have a Python script that asks users to authenticate via Kerberos. My program is basically this:

import subprocess

def kinit():
kinit = "kinit -f"
prompt = subprocess.check_output(kinit, shell=True)
print prompt ## echoes "Password for" AFTER pw input

if __name__=="__main__":

When this script is launched from the Terminal, the program waits for password input (which can be input via the command line), but it only displays the "Password for" prompt AFTER the user inputs their password.

Do you know how I can display the "Password for" before the Python script waits for them to input their password?


Turns out you can't. subprocess will not return output in the middle of a process, and the process will not complete until you input user input.