如何使用python获取Windows中的Unix可执行位?

时间:2019-03-24 04:27:09

标签: python windows file-permissions

我正在尝试获取Windows中文件的可执行位,我希望结果与Unix中的相同。

在Windows中,使用Git Bash,ls -l的结果显示名为test.sh的文件的模式为-rwxr-xr-x

仍然在Windows中,使用python,命令和相应的输出如下所示,其中0o666-rwxr-xr-x不同。

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat('test.sh')
os.stat_result(st_mode=33206, st_ino=1125899907017545, st_dev=3596032845, st_nlink=1, st_uid=0, st_gid=0, st_size=37, st_atime=1553395775, t_mtime=1553395775,
st_ctime=1553395775)
>>> oct(33206)
'0o100666'
>>>

获取相同的可执行位是否可行?还是上面的任何动作是错误的?

谢谢您的建议。

要创建提到的test.sh,我只是在Git Bash中用vim键入了以下内容

#!/usr/bin/env bash
echo Hello World

0 个答案:

没有答案