gpt4 book ai didi

python - 如何将多个变量从Python脚本传递到C shell脚本

转载 作者:行者123 更新时间:2023-11-30 18:55:14 25 4
gpt4 key购买 nike

我确实知道如何将一个变量从 python 传递到 c shell 脚本,但我在将多个 python 变量传递到 c shell 脚本时遇到了麻烦。请让我知道我们如何实现这一目标。这是我了解到将单个变量从 python 传递到 c shell 脚本的链接。

How to pass the Python variable to c shell script

最佳答案

将每个参数作为单独的 argv 条目传递:

first_var='hello'
second_var='world'
subprocess.Popen(['program_name', first_var, second_var], shell=False)

相比之下,如果您想通过环境传递多个变量,它们都应该是 env 字典中的键:

subprocess.Popen(['program_name'], env={
'first_var': first_var,
'second_var': second_var,
})

关于python - 如何将多个变量从Python脚本传递到C shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28238233/

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