When I run this two commands in Ubuntu terminal I get a variable value
1. source script.sh
2. echo $varname
Where scripts.sh contains the variable being defined which is than called with echo in step 2.
How do I accomplish the same in python script: I have tried the following code
#!/bin/bash
import subprocess
command=['bash','-c','source ia_servers']
cmdout = subprocess.Popen(command, stdout=subprocess.PIPE)
filtercommand=['bash','-c','echo $IA_SRV_cs68_64']
filtered = subprocess.Popen(filtercommand, stdin=cmdout.stdout, stdout=subprocess.PIPE)
output, err = filtered.communicate()
print(output)
Description: I first ran step 1 using subprocess and the result of it fed as input to the step 2. I know there wont come any output in the first steps. But how do I accomplish this in python.
Or am I following the wrong way. If there is another way to solve this problem
Primary Goal:
my purpose is to get the variable value being set in the bash scripts to my python codes.