title: Using Source Command From A Python Script
body: <p>I was tring to call the source command in unix from a python script. I was trying to get it done with subprocess.Popen passing the os environment to it.</p>
  
  <p>Below is my function for doing the task of executing a command:</p>
  
  <pre><code>def run_command(command, tst_env):
      print tst_env
      try:
         p = subprocess.Popen(command, env=tst_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
         stout, er = p.communicate()
         print stout, er
         ret = p.wait()
      except Exception, e:
         print "Exception: ", e
      else :
          if ret:
            print command, "failed", ret
            return
          else:
            print command, "succeeded", ret
      return p
  </code></pre>
  
  <p>The <code>tst_env</code> is an object of os.environ type.</p>
  
  <p><code>run_command(source script.sh, os.environ)</code> says it is successful.</p>
  
  <p>But I am not able to access the functions in the script.</p>
  
  <p>The case is like this:</p>
  
  <p>script.sh follows:</p>
  
  <pre><code>function task_test() {
     echo "Test function called"
  }
  
  source script.sh
  </code></pre>
  
  <p><code>task_test</code> will call the function in the shell script.</p>
  
  <p>But I am not able to call the functions in the shell script from python.</p>
  
  <p>Hope I am clear.</p>