Próbuję uruchomić polecenie dir w linii komend i zczytać wynik do zmiennej.
to działa:
output1 = os.popen('dir')
print(output1.read())
natomiast check_output zwraca błąd, dlaczego?
output = subprocess.check_output("dir")
Traceback (most recent call last):
File "C:/Users/Python/AppData/Local/Programs/Python/Python35-32/manipulacje plikami.py", line 17, in <module>
output = subprocess.check_output("dir")
File "C:\Users\Python\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 629, in check_output
**kwargs).stdout
File "C:\Users\Python\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Python\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in init
restore_signals, start_new_session)
File "C:\Users\Python\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Nie można odnaleźć określonego pliku