Hi, I’d like to write to an existing file.
touch cmds #ran in linux to creat an empty file
then in Julia I did:
for i in 1:5
cmd= "echo hello
close(cmds) #tick appears but the existing file is still empty
Could anyone give a hint for what’s wrong?
Your code snippet works for me. My guess is that the file you created with
touch is not in your julia working directory. Note that
open("filename", "w") will overwrite the contents of “filename” or create that file if it doesn’t exist. So if your julia working directory is not the directory where you ran
touch cmds, then when you run `cmds = open(“cmds”, “w”) in julia it’s actually creating a new file called cmds.
Thank you, so I checked with
pwd() before running the codes.
In this case, after running the codes are still empty when I checked in linux(Ubuntu).
However, this problem is solved after
ls in linux. The empty file started being written. (though have no idea why–can
ls refresh linux subtly?)