Python 3 subprocess module throws error running quot;dirquot; on Windows(Python 3 子进程模块在运行“dir时抛出错误.在 Windows 上)
问题描述
Python 3 中的这个简单程序会引发错误.可能是什么原因?这个问题是在我安装/重新安装 Python 3.5/3.6 之后出现的.Python 2.7 也安装在我的 PC(Windows 10 机器)上.
This simple program in Python 3 throws errors. What could be the reason? This problem arose after I installed/reinstalled Python 3.5/3.6. Also Python 2.7 is installed on my PC (windows 10 machine).
import subprocess
out = subprocess.check_output(['dir'])
错误信息:
文件C:Python36libsubprocess.py",第 336 行,在 check_output 中**kwargs).stdout
File "C:Python36libsubprocess.py", line 336, in check_output **kwargs).stdout
文件C:Python36libsubprocess.py",第 403 行,运行中使用 Popen(*popenargs, **kwargs) 作为进程:
File "C:Python36libsubprocess.py", line 403, in run with Popen(*popenargs, **kwargs) as process:
init 中的文件C:Python36libsubprocess.py",第 707 行restore_signals, start_new_session)
File "C:Python36libsubprocess.py", line 707, in init restore_signals, start_new_session)
文件C:Python36libsubprocess.py",第 990 行,在 _execute_child 中启动信息)
File "C:Python36libsubprocess.py", line 990, in _execute_child startupinfo)
FileNotFoundError: [WinError 2] 系统找不到文件指定
FileNotFoundError: [WinError 2] The system cannot find the file specified
推荐答案
不是可执行文件,而是 内置到外壳.Python subprocess 模块找不到,所以报错了.
It's not an executable, but built-in to the shell. Python subprocess module can't find it, so you got an error.
如果您想使用 subprocess 模块,请使用一些现有的二进制文件,例如python、notepad 或 ping.如果您需要列出文件夹内容,请使用 os.listdir 或 os.walk.
If you would like to play with subprocess module, use some existing binary, e.g. python, notepad or ping.
In case you need to list folder content, please use os.listdir or os.walk.
这篇关于Python 3 子进程模块在运行“dir"时抛出错误.在 Windows 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 3 子进程模块在运行“dir"时抛出错误.在 Windows 上
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
