I'm trying to run a shell script in python and save the output to a variable.
This is my python script:
import os
os.system("sh ./temp.sh > outfile.txt")
file = open("outfile.txt", "r")
var = file.readLine()
#I do more stuff using var
Right now this works. However is there a more efficient way to do this? It seems a little inefficient to output to a file and then read from the file again. My goal is to set var directly from the output of the os command. For example var = os.system(unix command). (I know this doesn't work).