python - 将值从 bash 传输到 python 脚本

标签 python linux bash command-line

我在 bash 中有一个名为“Nautilus Script”的脚本。它可以从系统文件夹执行,用于对选定的文件进行自定义操作:

#!/bin/bash

while [ $# -gt 0 ]; do
    file=$1
    #doing smf with selected file
    shift
done

此外,我知道在 cmd 中使用自定义 python 脚本启动 Blender 的能力:

blender -b blendfile.blend -P script.py -x 1 -F PNG -f 1

我想获取一个值file并将其传输到Python脚本中以在script.py中使用它:

#!/bin/bash

while [ $# -gt 0 ]; do
    file=$1
    blender -b blendfile.blend -P script.py//+put here $file// -x 1 -F PNG -f 1     
    shift
done

我该怎么做?

关于this answer : 注意,python 脚本在 Blender 中启动,而不是在 bash shell 中

最佳答案

来自blender.stackexchange

Blender 会忽略 -- 之后的所有参数,而 Python 不会。您可以在Python中搜索--并使用

读取其后面的所有参数
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:]  # get all args after "--"

您将传入的参数如下所示

blender -b blendfile.blend -P script.py -x 1 -F PNG -f 1 -- $file

关于python - 将值从 bash 传输到 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42829868/

相关文章:

python - 是否可以使用 python 从外汇中读取真实的实时(能源和金属)数据

linux - 计算文件中 2 个字符串之间匹配的行数

bash - 在 bash 脚本中找不到 mkdir 命令

bash - 从命名管道捕获非零退出代码

python - 在 python 中使用 np.where 函数时如何避免 NaN?

python - 恢复丢失的 multiprocessing.Queue 项目,当工作进程死亡时

c - 出于性能原因将代码推送到内核或用户空间?

bash - 如何提取tar文件中的tar文件

python - 在 Python 中合并图像

python - pip 无法安装 psycopg2。通过 apt-get 安装,但构建文件夹仍然存在