获取shell脚本"读"从python脚本值 [英] Get shell script "read" value from python script

查看:123
本文介绍了获取shell脚本"读"从python脚本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

shell脚本:
Hello.sh

Shell script: Hello.sh

#!/bin/bash
echo "Enter your name: "
read name
echo "Hello $name"

我想从蟒蛇中调用Hello.sh并填写变量名非交互方式。
如何能做到?

I want to invoke Hello.sh from within python and fill variable "name" non-interactively. How can it be done?

推荐答案

不知道如何读你的问题。

Not sure how to read your question.

编辑:评论是由OP补充说:
在Python中调用Hello.sh和补非交互式的名字

Comment was added by the OP: invoke Hello.sh from within python and "fill" name noninteractively

这改变的事情,所以这里是新的问题不同的回答:

Which changes things, so here is a different answer for the new question:

import subprocess
cmd = '/home/user1/Hello.sh'
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
proc.communicate("Fred Bloggs")

我已经使用的完整路径剧本,是比较安全的。

I have used the full path to the script, it is safer.

这篇关于获取shell脚本"读"从python脚本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆