I am getting a weird "Access denied - \" error\warning when I run the following script:
import os
import subprocess
directory = r'S:\ome\directory'
subprocess.run(['find', '/i', '"error"', '*.txt', '>Errors.log'], shell=True, cwd=directory)
I have also checked:
print(os.access(directory, os.R_OK)) # prints True
print(os.access(directory, os.W_OK)) # prints True
and they both print
True
.
The error message is printed while the subprocess
command is running but the process is not killed; nothing is raised. As a result, wrapping it into a try-except
even without specifying the exception is not catching anything. When the process finishes, the file is created (Error.log
) but contains the wrong results.
Running the exact same command (find /i "fatal" *.txt >Error.log
) from a cmd opened in the specified directory produces the correct results.
So in which way are the two approaches different?
Approach 1 (from Python):
subprocess.run(['find', '/i', '"error"', '*.txt', '>Errors.log'], shell=True, cwd=r'S:\ome\directory')
Approach 2 (from cmd):
S:\ome\directory>find /i "error" *.txt >Errors.log