Write() done but not writing the content in existing file

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:

cmds=open("cmds", "w")
for i in 1:5
    cmd= "echo hello
echo byebye"
    #write(cmds, join(cmd,"\t","\n"))
    write(cmds, cmd)

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 readdir() and 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?)