1
final="cacls " + "E:/" + "\"" + list1[2] + " " + list1[3] + "\""  + "  /p " + str
os.system(final)

I am trying to set permission to a folder Using Python but while running this command , User input needs to be provided too i.e

it asks ARE YOU SURE(Y/N) and the user needs to enter "Y" or "N"

Is there any way to use python to send the user input "Y" along with the above code?

    pro = subprocess.Popen(final,shell=True, stdin=subprocess.PIPE)
    pro.communicate(bytes("Y\r\n",'utf-8'))

I have added the following code . The program exits without setting the permission.

http://jimmyg.org/blog/2009/working-with-python-subprocess.html#writing-to-standard-input

1
  • Aparte from your question: this is not PHP or Javascript - Python hamore readable ways of concatening strings, and they are much better. For example, try: `final = "cacls %s\"%s %s\" /p %s" % ("E:/", list1[2], list1[3], str) Commented Apr 5, 2012 at 13:03

2 Answers 2

3

Try using the subprocess module

import subprocess
cmd = ["cacls",  "E:/" + list1[2], list1[3], "/p", str]

pro = subprocess.Popen(final, stdin=subprocess.PIPE)
pro.communicate("y\r\n")
Sign up to request clarification or add additional context in comments.

8 Comments

Hi jakob , i tried your solution, The program never exits and the permissions are not set
The same output , this time i can see the cacls.exe being executed. The program doesnt exit.
1. Use a list instead of a string to pass arguments; that allows you to get rid of all the silly quoting that will eventually break. 2. Try "y\r\n" instead of "y"
It might also be a suggestion to use str.format so building these sort of strings just becomes much more beautifull?
Hi Aaron, still the same problem.
|
-1

As a smart programmer, use PBS

Then, the code is:

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())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.