简体   繁体   中英

Python subprocess using Idle

I am new to python scripting. I am trying to run subprocess methods on Python Idle and getting these errors:

import subprocess
subprocess.check_output("ls")

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 336, in check_output
  **kwargs).stdout
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 403, in run
  with Popen(*popenargs, **kwargs) as process:
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
  restore_signals, start_new_session)
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
  startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Please help me out to resolve this error. Thank you

seems like you are running windows. Windows has no "ls" command, so you get a FileNotFoundError exception. I am not familiar with windows and python, but try "dir" instead of "ls", that should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM