【发布时间】:2013-02-19 18:59:59
【问题描述】:
我正在尝试编写一个 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.
【问题讨论】:
-
echo "read this!" | python hello.py- 我们到底在说什么外壳? -
这看起来像一个UUOE(与UUOC密切相关)
-
还可以查看this answer,了解 Python 中的自动化测试和标准输入。