【发布时间】:2025-12-28 13:25:16
【问题描述】:
第 17.1.1.1 节。的documentation 状态:
如果 shell 为 True,指定的命令将通过 shell 执行。如果您将 Python 主要用于它在大多数系统 shell 上提供的增强控制流,并且仍然希望方便地访问其他 shell 功能,例如 shell 管道、文件名通配符、环境变量扩展和 ~ 到用户家的扩展,这将很有用目录。
然而,在 cygwin 上,bash 的输出与 Python 的子进程 的输出不同,即:
重击:
$ ls -ls ~rbarakx
total 0
0 drwxr-xr-x 1 Administrator None 0 Aug 21 17:54 bash
0 drwxr-xr-x 1 Administrator None 0 Jul 11 09:11 python
Python:
>>> subprocess.call(["ls","-ls","~rbarakx"],shell=True)
RCS mecha.py print_unicode.py req.py requests_results.html selen.py
0
看起来好像 subprocess.call 只是在执行 ls。
你能说出原因吗?
我的环境:
Python:Python 2.7.3(默认,2012 年 12 月 18 日,13:50:09)[GCC 4.5.3] 开启
cygwin
cygwin:CYGWIN_NT-6.1-WOW64 ... 1.7.22(0.268/5/3) ... i686
Cygwin
windows:Windows 7 Ultimate
【问题讨论】:
标签: python bash shell cygwin subprocess