final="cacls " + "E:/" + "\"" + list1[2] + " " + list1[3] + "\"" + " /p " + str
os.system(final)
我正在尝试设置使用Python的文件夹的权限,但在运行此命令时,也需要提供用户输入,即
它问你是否确定(是/否)并且用户需要输入“Y”或“N”
有没有办法使用python发送用户输入“Y”和上面的代码?
pro = subprocess.Popen(final,shell=True, stdin=subprocess.PIPE)
pro.communicate(bytes("Y\r\n",'utf-8'))
我添加了以下代码。程序退出时未设置权限。
http://jimmyg.org/blog/2009/working-with-python-subprocess.html#writing-to-standard-input
答案 0 :(得分:3)
尝试使用子流程模块
import subprocess
cmd = ["cacls", "E:/" + list1[2], list1[3], "/p", str]
pro = subprocess.Popen(final, stdin=subprocess.PIPE)
pro.communicate("y\r\n")
答案 1 :(得分:-1)
作为智能程序员,请使用PBS
然后,代码是:
from pbs import type as echo# Isn't it echo for Windows? If not, use the correct one
script = Command("/path/to/cacls ")
print script(echo("Y"), ("E:/" + "\"" + list1[2] + " " + list1[3] + "\"" + " /p " + str).split())