python-2.7 - 使用 gitbash 在 python 中重定向
问题描述
$ python -i test.py
系统找不到指定的路径。(system could not find the path)
>>> Stopped
$ cat test.py
#!/usr/bin/python
import os
cmd = "ls -l >/dev/null 2>&1"
os.system(cmd)
当我在带有 gitbash 的 Python 中使用标准输出重定向时,它只是不起作用,而在直接在 gitbash 中运行命令时它却运行良好。
$ ls -l >/dev/null 2>&1
有没有人遇到过这个问题或可能会提供帮助?
解决方案
我在下面的链接下找到了根本原因,希望它可以帮助更多 https://superuser.com/questions/777198/equivalent-of-foo-dev-null-in-windows-shell
推荐阅读
- python - Python SqlAlchemy + MySql 按 JSON 列数据过滤
- python-3.x - Python Pandas read_csv():错误加载的 csv
- ios - 如何在没有 ViewControllers 的情况下使用 SwiftUI 获取当前位置?
- c# - 在给定的文化中查找不区分大小写的字符串的第一个区别
- mysql - 错误:“SQLSTATE [42000]:语法错误或访问冲突:1064
- python - AttributeError:“配置”对象没有属性“测试系统”
- javascript - 如何将点属性名称转换为 JavaScript 中的结构化嵌套对象?
- angular - Angular 8 遥测共享选择加入
- javascript - 为未知数量的深度递归地设置 CSS 类的样式
- postgresql - 如何在不使用 GROUP BY 子句的情况下对行进行分组