2

I have a python script which requires a value from a shell script.

Following is the shell script (a.sh):

#!/bin/bash
return_value(){
  value=$(///some unix command)
  echo "$value"
}

return_value

Following is the python script:

Import subprocess
answer = Subprocess.call([‘./a.sh’])
print("the answer is %s % answer")

But its not working.The error is:

ImportError : No module named subprocess

I guess my verison (Python 2.3.4) is pretty old. Is there any substitute for subprocess that can be applied in this case??

jfs
  • 399,953
  • 195
  • 994
  • 1,670
user2475677
  • 149
  • 2
  • 5
  • 11

1 Answers1

4

Try commands module for py2.3.4, note that this module has been deprecated since py2.6:

Use commands.getoutput:

import commands
answer = commands.getoutput('./a.sh')
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
  • 1
    It worked !!!! How do you think of this? I know our team needs to update our python version but Thanks a lot ! – user2475677 Jun 21 '13 at 17:35