[英]Django 1.9 : Pass variables from python script to bash script - OSError : [Errno 2] No such file or directory
subprocess.call(["echo",instance.Username]) # => works .
subprocess.call(["username=",instance.Username]) # => error
subprocess.Call(["username","=",instance.Username]) # => error
subprocess.call(["username=",instance.Username],shell=True)
# => no Error but when i do echo $username there is nothing inside..
would you help me, I just want to put the value of instance.Username in a bash variable. 您能帮我吗,我只想将instance.Username的值放在bash变量中。
Thank you. 谢谢。
You'll want to pass it as an environment variable to subprocess.call()
like so: 您将希望将其作为环境变量传递给
subprocess.call()
如下所示:
env = {
'username': instance.Username,
}
subprocess.call(['./your_script.sh'], env=env)
This will make the environment variable $username
available to your bash script. 这将使环境变量
$username
可用于bash脚本。
Remember to enclose the bash command in a list, run the script with ./
, and start the script with the correct shebang, (all things I forgot to do while writing this). 请记住,将bash命令括在列表中,使用
./
运行脚本,并使用正确的shebang启动脚本(所有我在编写此文件时忘记做的事情)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.