Python的子进程不跨preT"〜"如预期的cygwin上 [英] Python's subprocess does not interpret "~" as expected on cygwin

查看:79
本文介绍了Python的子进程不跨preT"〜"如预期的cygwin上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第17.1.1.1。 文档状态:

Section 17.1.1.1. of the documentation states:

如果外壳为True,指定的命令将通过在shell执行。这可如果你正在使用Python主要是为加强控制流它提供了最系统外壳,仍然需要其他外壳的功能,如壳管,文件名通配符,环境变量扩展,并〜扩展到用户的家中方便地访问有用。目录

If shell is True, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory.

不过,在的cygwin 的,从输出的庆典的是不一样的,从的 Python的子的,即:

However, on cygwin, output from bash isn't the same as from Python's subprocess, viz:

击:

$ 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


您能否为什么?的搜索结果

It looks as if subprocess.call is executing just ls.

Can you suggest why?

我的环境:结果
的Python :Python的2.7.3(默认情况下,2012年12月18日,十三时50分09秒)[GCC 4.5.3]上
cygwin的结果的cygwin :CYGWIN_NT-6.1-WOW64 ... 1.7.22(0.268 / 5/3)... i686的
Cygwin的结果窗口:Windows 7旗舰版

My Environment:
Python: Python 2.7.3 (default, Dec 18 2012, 13:50:09) [GCC 4.5.3] on cygwin
cygwin: CYGWIN_NT-6.1-WOW64 ... 1.7.22(0.268/5/3) ... i686 Cygwin
windows: Windows 7 Ultimate

推荐答案

在Windows中,外壳(的cmd.exe )不支持的扩展到用户的主目录。也不是通配符扩展,为这一问题。 Python的文档是在这一点上是非常的UNIX / Linux为主。

On Windows, the shell (cmd.exe) doesn't support the expansion of ~ to a user's home directory. Nor wildcard expansion, for that matter. The Python doc is very UNIX/Linux-oriented on this point.

别急!我听见你哭。 我已经安装了的cygwin ,我有庆典!当然你有,但你很难指望Python来知道。您使用的是Windows,所以它要使用Windows外壳程序。如果没有,Python脚本,人们期望外壳为的cmd.exe 将是强大的混淆。

"But wait!" I hear you cry. "I've installed cygwin, I have bash!" Sure you have, but you can hardly expect Python to know that. You're on Windows, so it's going to use the Windows shell. If it didn't, Python scripts that expected the shell to be cmd.exe would be mighty confused.

这篇关于Python的子进程不跨preT"〜"如预期的cygwin上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆