Skip to main content
 首页 » 编程设计

python之从 shell 向 python 脚本提供输入

2025年05月04日19zfyouxi

我正在尝试编写一个 shell 脚本来运行一个接受一些原始输入的 python 文件。 python 脚本基本上是这样的:

def main(): 
    name=raw_input("What's your name?") 
    print "Hello, "+name 
main() 

我希望 shell 脚本运行脚本并自动将输入输入其中。我已经看到很多方法可以从 python 函数返回的内容中获取 shell 输入,或者如何使用输入从 python 运行 shell,但不是这样。基本上,我只想要一些能做的事情:

python hello.py 
#  give the python script some input here 
#  then continue on with the shell script. 

请您参考如下方法:

你的意思是:

python hello.py <<EOF 
Matt 
EOF 

这被称为 bash HERE document .