简体   繁体   English

Django 1.9:将变量从python脚本传递到bash脚本-OSError:[Errno 2]没有这样的文件或目录

[英]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.

相关问题 在终端中运行 python 脚本时出错:OSError: [Errno 2] No such file or directory - Error running python script in terminal: OSError: [Errno 2] No such file or directory Traceroute的Python脚本和在文件中打印输出显示Linux Mint中的错误(OSError:[Errno 2]没有这样的文件或目录) - Python Script for Traceroute and printing the output in file shows error( OSError: [Errno 2] No such file or directory) in Linux Mint Python OSError:[Errno 2]没有这样的文件或目录 - Python OSError: [Errno 2] No such file or directory Python:OSError:[Errno 2]没有这样的文件或目录 - Python : OSError: [Errno 2] No such file or directory Python:OSError:[Errno 2] 没有那个文件或目录:'' - Python: OSError: [Errno 2] No such file or directory: '' OSError:[Errno 2]没有这样的文件或目录:php shell_exec [AWS-Lambda]内部的[python脚本] - OSError: [Errno 2] No such file or directory : [python script] inside php shell_exec [ AWS-Lambda] OSError: [Errno 2] 在 Django 中使用 python 子进程时没有这样的文件或目录 - OSError: [Errno 2] No such file or directory while using python subprocess in Django 如何将变量从 python 脚本传递到 bash 脚本 - How to pass variables from python script to bash script pyinstaller和django OSError:[Errno 2]没有这样的文件或目录 - pyinstaller & django OSError: [Errno 2] No such file or directory 将变量从python文件传递给bash脚本 - Pass variable from python file to bash script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM