首页 > 解决方案 > 使用 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

有没有人遇到过这个问题或可能会提供帮助?

标签: python-2.7

解决方案


我在下面的链接下找到了根本原因,希望它可以帮助更多 https://superuser.com/questions/777198/equivalent-of-foo-dev-null-in-windows-shell


推荐阅读