在 python 中使用子进程时在 cmd 中提示
Prompt in cmd when using subprocess in python
我有这个代码:
command = "runas /user:theuser cmd"
subprocess.run(command)
此处 cmd 向用户询问密码
我的问题是我是否可以使用 python?
在此处输入密码
您应该改用 subprocess.Popen
。这意味着您可以与程序通信:
command = "runas /user:theuser cmd"
p = Popen([command], stdout=PIPE, stdin=PIPE, stderr=PIPE)
p.communicate(input='data')[0]
您可以查看 The docs 了解更多信息
我有这个代码:
command = "runas /user:theuser cmd"
subprocess.run(command)
此处 cmd 向用户询问密码 我的问题是我是否可以使用 python?
在此处输入密码您应该改用 subprocess.Popen
。这意味着您可以与程序通信:
command = "runas /user:theuser cmd"
p = Popen([command], stdout=PIPE, stdin=PIPE, stderr=PIPE)
p.communicate(input='data')[0]
您可以查看 The docs 了解更多信息