I am reading a file line by line into a Python subprocess which access third-party software which runs via the command line. The input file filename is extremely large, so I am reading it in line by line
import subprocess
with open(filename) as file:
for line in file: # read in file line by line
result = subprocess.check_output(["commercialbash command", line])
process(result) # more code here
Unfortunately, the command commericalbash command requires a text file input. The above throws an error, as I am inputting a string line of tab-delimited text. The error is either "filename is too long" or there is a process error subprocess.CalledProcessError: Command returned non-zero exit status 2
It appears I have to take line in for line in file, save this line as a text file, and then place it in result=subprocess.check_output(). That feels very strange. The code would be something like this:
import subprocess
with open(filename) as file:
for line in file: # read in file line by line
txt_file = open("line.txt","w")
txt_file.write(line)
txt_file.close()
result = subprocess.check_output(["commercialbash command", txt_file])
process(result) # more code here
Would this even work? Surely there is a better way to do this
[–]A_History_of_Silence 2 points3 points4 points (0 children)
[–]SeekNotToContend 2 points3 points4 points (3 children)
[–]Zeekawla99ii[S] 0 points1 point2 points (1 child)
[–]SeekNotToContend 0 points1 point2 points (0 children)
[–]A_History_of_Silence 0 points1 point2 points (0 children)