【问题标题】:Transfer values from bash to python script将值从 bash 传输到 python 脚本
【发布时间】:2017-03-16 09:23:10
【问题描述】:

我在 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 -b blendfile.blend -P script.py "$1" -x 1 -F PNG -f 1 不符合您的要求吗?
  • @tripleee 来自 Nils Werner 的回答。 This answer 解释了为什么这种简单的方法行不通

标签: python linux bash command-line


【解决方案1】:

来自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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2022-08-24
    • 2019-03-11
    • 2011-06-26
    • 2013-03-26
    • 2011-04-26
    • 1970-01-01
    相关资源
    最近更新 更多