使用Idle的Python子进程

时间:2017-06-01 19:18:38

标签: python subprocess

我是python脚本新手。我试图在Python Idle上运行子进程方法并得到这些错误:

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

请帮我解决此错误。 谢谢

1 个答案:

答案 0 :(得分:0)

好像你正在运行Windows。 Windows没有&#34; ls&#34;命令,所以你得到FileNotFoundError例外。我不熟悉windows和python,但试试&#34; dir&#34;而不是&#34; ls&#34;,这应该有用。