【发布时间】:2012-04-05 12:04:23
【问题描述】:
final="cacls " + "E:/" + "\"" + list1[2] + " " + list1[3] + "\"" + " /p " + str
os.system(final)
我正在尝试使用 Python 设置文件夹的权限,但是在运行此命令时,也需要提供用户输入,即
它询问您是否确定(Y/N),用户需要输入“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
【问题讨论】:
-
除了你的问题:这不是 PHP 或 Javascript - Python hamore 可读的连接字符串的方式,而且它们要好得多。例如,尝试:`final = "cacls %s\"%s %s\" /p %s" % ("E:/", list1[2], list1[3], str)