>> subpr-6ren">
gpt4 book ai didi

python - Python 子进程模块中 PATH 的使用

转载 作者:行者123 更新时间:2023-11-28 22:38:28 25 4
gpt4 key购买 nike

我偶然发现 Python 的 subprocess 有一个奇怪的行为模块:

>>> import os, subprocess
>>> del os.environ["PATH"]
>>> subprocess.run(["python", "--version"])
Python 3.5.1
CompletedProcess(args=['python', '--version'], returncode=0)

我想知道如何在未设置 PATH 环境变量的情况下运行该命令?有没有默认的PATH

最佳答案

是的,有一个默认的 PATH,至少在 Linux 中是这样。

请考虑 Linux execl() man page 中的这句话:

If [the PATH variable] isn't defined, the path list defaults to the current directory followed by the list of directories returned by confstr(_CS_PATH). (This confstr(3) call typically returns the value "/bin:/usr/bin".)

关于python - Python 子进程模块中 PATH 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com