Reputation: 23
I am trying to run a program from within Python and redirect that output to a new file that I will read into another program later. Is there some other way I should be doing this other than "%s>%s"?
distmathandle = open("newfile.distmat", "w")
cmd = "quicktree -out m %s>%s" % (stfname,distmathandle)
sys.stderr.write("command: %s\n" %cmd)
os.system(cmd)
sys.stderr.write("command done\n")
distmathandle.close()
Upvotes: 0
Views: 165
Reputation: 12263
You are passing a file object to the command, but that just expects the name of the file to redirect output to.
Just try:
cmd = "quicktree -out m %s>newfile.distmat" % (stfname)
And remove open()/close() of that file. Or use a string variable for the filename and use your previous line. However, you should not have the file open from two processes at the same time.
The command executed has no knowledge about objects inside of the Python program it is called from.
Upvotes: 1