【问题标题】:Passing input to python script invoked by shell script [duplicate]将输入传递给由shell脚本调用的python脚本[重复]
【发布时间】:2017-08-07 01:36:57
【问题描述】:

我的 shell 脚本像这样调用 python 脚本:

python take_user_input.py

take_user_input.py 脚本在被调用后要求用户输入,如下所示:

$ python take_user_input.py
Please enter your username: <expects user to enter username>
Please enter your email: <expects user to enter email>

我无法修改take_user_input.py 脚本,因为它是另一个包的一部分。

问题:是否可以在 shell 脚本中指定用户名和电子邮件,以便在调用 python 脚本后自动获取这些值?

【问题讨论】:

标签: python bash shell


【解决方案1】:

您可以使用此处的文档。

python take_user_input.py << EOF
me
me@email.com
EOF

【讨论】:

    【解决方案2】:

    是的

    printf "my_username\nmy_password\n" | python take_user_input.py
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 2020-10-02
      • 2022-01-23
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多