Why does the command break when I try to pipe a yes reply with echo in subprocess, but works perfectly fine when I manually enter it into the command prompt?
Notice I tried with and without spacing and the results are the same, but if you put either EXACTLY as you see it into command prompt, it works instead of giving the error
WindowsError: [Error 2] The system cannot find the file specified
C:\Windows\System32>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> p = subprocess.Popen("echo y|cacls {0} /d SYSTEM".format("C:\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>> p = subprocess.Popen("echo y|cacls {0} /d SYSTEM".format("C:\ProgramData\Microsoft\Diagnosis\ETLLogs\AutoLogger\AutoLogger-Diagtrack-Listener.etl", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>> p = subprocess.Popen("echo y| cacls {0} /d SYSTEM".format("C:\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>> p = subprocess.Popen("cacls {0} /d SYSTEM".format("C:\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE))
>>> Are you sure (Y/N)?
Notice it works at the end when I remove the echo completely, but then I can never actually finish running it because it never gets the "yes" (echo y|
) reply... and there isn't a /yes
switch built into the command, unfortunately.