Can't get seekend working on a manually updated csv file

Trying my first julia program and it’s not working. I want to add a line to an existing csv file and have julia monitor the file for any changes and print out the change. So I am seeking the current end of the file and I “THINK” the pointer should be at the current last byte location of the file. When I add a row I would expect the read to grab the new bytes once the 0.5 sec timer expires. But it isn’t seeing them.

I call the julia script from bash in Linux mint like this

$ julia j_csv_monitor.jl  /home/dave/Documents/test.csv

the code runs and prints out

/home/dave/Documents/test.csv

as expected so I know it’s looking at the correct location and file.

I have the test.csv file open in librecalc
I add a line hit return
save the csv
and the script prints nothing. It just sits there.

I know I’m looking at the right file AND the code gives no errors.

file_arg = ARGS[1]

println(file_arg)

file = open( file_arg )


seekend(file) # ignore contents that are already there 


while true
    sleep(0.5)
    data = read(file, String)
    !isempty(data) && print(data)
end

I know there are other ways to achieve this but I want to start simply. Any help would be appreciated.

I don’t think you can “update” a file without re-opening it, it can be complicated to predict what happens exactly:

but in general, don’t rely on the behavior, if you know you’re only appending, make Julia remember the last line number, and in the loop, re-open the file (and remember to close it) and jump to the line number.

1 Like

hi there @jling
as always excellent and on point guidance. The code WORKS with an OPEN active file where a python process is updating the text file every 5 seconds when I run it from the cli in the REPL

$ julia j_text_monitor.jl /tmp/test.csv

BUT not when I run it in the MANUAL mode above.

The link was VERY useful as it reminded me that I should have been looking at Linux rules not Julia’s. I am not sure why I thought this but in my mind the seekend(file) would have moved the pointer to the last byte of the file THEN the read(file) would start at that byte location and load up a buffer with what was read. Looking at my “code” I don’t see ANY reason for me to believe any of that so I’m going to go back and try again with my Linux hat on thanks to your help. Thanks again.