gpt4 book ai didi

python - 在 python 中获取 os.system 的输出并在之后处理它

转载 作者:太空宇宙 更新时间:2023-11-04 05:58:21 24 4
gpt4 key购买 nike

<分区>

我正在尝试做类似的事情:

f = subprocess.check_output("./script.sh ls -l test1/test2/test.log", shell=True)

当我打印 f 时,我得到值 0。我尝试使用 subprocess,然后使用 read(),但即使这样我也没有得到文件的详细信息。我需要验证文件的大小..

不知道怎么做。

有什么帮助吗?

当我使用

f = os.system("./script.sh ls -l test1/test2/test.log"),我得到了输出但没有保存在 f 中。像 stdoutput 之类的东西..

更新:我用过

f = os.popen("./script.sh ls -l test1/test2/test.log 2>&1")

如果我在上面的引号中运行相同的命令,直接在 CLI 上,它工作正常,但如果我在脚本中使用上面的命令或使用 s = f.readline(),脚本停止,我需要在脚本继续之前点击“返回”..

这是为什么呢?我需要 's' 因为我需要处理它。

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