i have problem with PermissionError: [WinError 5] permission denied. Can somebody tell my why?
import subprocess
run_shell = subprocess.run(['./', 'ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
test = str(run_shell.stdout.decode()).split('\n')
for el in test:
if not el:
continue
print(f"Plik: {el}")
print("Info: {}".format(run_shell.stderr.decode()))
Even if i am trying only with subprocess, I still have it.
import subprocess
subprocess.run(['./', 'ls'])
tried this, doesn't help.
subprocess.run([r'./', 'ls'])
Error:
Traceback (most recent call last):
File "c:\Users\gawiq\KodyPython\lekcja_5_8.py", line 4, in <module>
run_shell = subprocess.run(['./', 'ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Users\gawiq\AppData\Roaming\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\gawiq\AppData\Roaming\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\gawiq\AppData\Roaming\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Permission denied
PS C:\Users\gawiq\KodyPython>
I tried already in CLI with administrator rights: pip install pydirectory, python -m pip install --upgrade pip,
also i tried
pip install --user subprocess.run,
but then, i got this:
Python: 'list' object has no attribute 'read'
Python version 3.10.5 pip version-22.2.1 using Windows 10 Home 64-bit and VSC
Thanks for help!
CodePudding user response:
Your problem is probably that neither ls
nor ./
is avalid command for the Windows CLI