I am trying to log some data down - it is going well, but I want to do real time logging. Currently my code like this:
date = `cmd /c date /t`
time = `cmd /c time /t`
datestr = chomp(read(date,String))
timestr = chomp(read(time,String))
headerini = "DATE" * " " * "TIME" * "\r\n"
try
rm("myfile.txt")
catch
end
io = open("myfile.txt", "w");
write(io, headerini);
close(io)
for i = 1:5
io = open("myfile.txt","a");
datestr = chomp(read(date,String))
timestr = chomp(read(time,String))
table = datestr * " " * timestr * "\r\n"
println(table)
write(io, table);
sleep(5)
close(io)
end
I want to do it real time, which is working currently, but I constantly have to open and close the same file - when I tried to use append functionality it was not real time, but only when my script ended. Is the way I am doing it now correct or can I improve it?
Thanks @oxinabox will try to change it to that syntax.
You are right @johnh probably smarter to use Julia directly - the only reason for using CMD was in the beginning I tried to code as an batch file, but I got stuck so went and made it inside Julia instead - thanks for the link!