FileNotFound w subprocess.check_output

0

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

1

Za dokumentacją: https://docs.python.org/2/lib[...]rocess.html#popen-constructor

On Windows with shell=True, the COMSPEC environment variable specifies the default shell. The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable.

0

dzięki bardzo! samemu trudno wszystko dopatrzeć.

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0