简体   繁体   中英

Prompt in cmd when using subprocess in python

I have this code:

command = "runas /user:theuser cmd"
subprocess.run(command)

and here cmd asks for password to theuser My question is if I can enter the password here using python?

You should use subprocess.Popen instead. This means you can communicate with the program:

command = "runas /user:theuser cmd"
p = Popen([command], stdout=PIPE, stdin=PIPE, stderr=PIPE)
p.communicate(input='data')[0]

You can check out The docs for more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM