I tried to print the number of line using 'wc -l' command using subprocess. It outputs that the file is empty while it is not.
import os
import subprocess
import tempfile
import time
filename = '/tmp/aaaaa'
with open(filename, 'w') as fout:
fout.write('1')
with open(filename) as fin:
print(fin.readlines())
subprocess.check_call('wc -l {}'.format(filename), shell=True)
Output:
['1']
0 /tmp/aaaaa
Why does it happen? My python version is 2.7.16.