How to use C program directly without using files?
I would like to use C program in SageMath. The way I do it is as follows:
fp1='r4.txt'
fp2='commandToRunC.txt'
fp3='HL8results18.txt'
F1 = open(fp1,'w')
for j in p1:
F1.write(chr(j+48))
F1.write(str(' '))
for j in p2:
F1.write(str(j))
F1.write(str('\n'))
F1.close()
F1 = open(fp2,'w')
F1.write("./a.out ")
F1.write(str(kk))
F1.write(" r4.txt | awk '{print $NF}' > HL8results18.txt")
F1.close()
import os
with open(fp2, 'r') as fp:
L = fp.readline()
cmd = L
os.system(cmd)
This works but I need to rewrite the data in txt files r4.txt, commandToRunC.txt, HL8results18.txt each time. The computation I am doing is quite large. So I would like to not to write the results to files but use them directly in SageMath. Is there some way to do this? Thank you very much.
Using subprocess, you can do things like:
Why do you create the file fp2? You may just create the list of commands
L
yourself in the script.@Sebastien, thank you very much! I will try your suggestions.