python - 无法让 findstr 与在 Windows 上运行的子进程一起工作
问题描述
我想从我的 python 环境中运行 findstr,但在使用 subprocess run 调用时我无法让它工作(我可以使用 dos 提示符从命令行运行 findstr 命令):
commandlist = ['findstr', '/s', '"texttofind"', '*.py']
cwd = 'e:\\python'
shell = True
encoding = 'utf-8'
output = subprocess.run(commandlist,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding=encoding, shell=shell, cwd=cwd)
最终返回码为 1:
CompletedProcess(args=['findstr', '/s', '"runrcode"', '*.py'],returncode=1, stdout='', stderr='')
相反,如果我使用 commandlist = ['path'] 那么一切正常,导致返回码为 0 和 stdout 以及预期的路径文本列表(当然 shell 必须为 True 才能工作)。
关于如何让它发挥作用的任何想法?不知道我错过了什么。非常感谢。
解决方案
推荐阅读
- angular - 如何在 ng2-datepicker 中设置仅选择年份选项?
- android - 无法显示带有毕加索的 .jpg 图片
- javascript - 将本地存储用于 css 切换开关时遇到问题
- asp.net - 如何使用 ASP.NET MVC 在 View 中设置 DropDownList 的默认值?
- jquery - 将html字段值传递给JQuery
- python - 应用 n.where 后如何重塑 Numpy 数组?
- scrapy - 蜘蛛在处理一个项目一小时后停止
- python - Python os.popen 引号内的引号错误
- android - 不要在 android 8.0.0 上隐藏导航抽屉
- graphene-django - DjangoObjectType 的 graphene-django 自定义 get_queryset 不起作用