1

Shell script: Hello.sh

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

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

4
  • 2
    what do you mean by "from a python script" ??? Commented Mar 21, 2013 at 13:08
  • 2
    do you want to give the value from variable "name" to a python script or get the variable name from a python script? Commented Mar 21, 2013 at 13:17
  • 2
    To clarify: he likely wants to invoke Hello.sh from within python and "fill" name noninteractively. If so, I believe that the answer John's looking for is to use subprocess and write to the stdin handle. Commented Mar 21, 2013 at 13:27
  • Exactly what Brian Cain is saying is what I m looking for. Commented Mar 21, 2013 at 13:33

2 Answers 2

1

Not sure how to read your question.

EDIT: 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.

Sign up to request clarification or add additional context in comments.

1 Comment

invoke Hello.sh from within python and "fill" name noninteractively
0
name = raw_input('Enter your name: ')
print 'Hello ', name

1 Comment

invoke Hello.sh from within python and "fill" name noninteractively

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.