【发布时间】:2018-01-18 14:57:48
【问题描述】:
我想将变量从 python 传递到 shell 脚本。我的代码如下所示。
Object_Id=12
Class_Name='My_Class'
Folder_Path='/My_Folder'
output=subprocess.check_output(['./execute.sh, 'Object_Id', 'Class_Name', "shell=True"])
print(output)
execute.sh 脚本只是简单的 echo 语句
echo $1
echo $2
输出是
Object_Id
Class_Name
脚本将 args 作为文字字符串获取,但我想获取变量的值。
【问题讨论】:
-
您能说明传递变量和获取参数之间的区别吗?如果你想传递变量 bash
export可能是你的电话。您可以随时编写如下代码:OBJECT_ID=$1; CLASS_NAME=$2
标签: python python-3.x shell subprocess