stegro
14th October 2013, 23:42
Hello,

with the seq..... commands I initiate a file on our unix server and write things in it. Unfortunatly it doesn't work properly: the first time I call the functions it just writes the file, but does not fill the information in. In the second run it writes the lines.
But: altogether I wanted to write two files. In the first run it doesn' t even write the first file, in the second run the file is written but with no content.

Thats my sourcecode:

fp.log = seq.open (trim$(f.log.path)&trim$(tmp.log), "a")
if fp.log <= 0 then
mess(...., 1, tmp.log)
|Datei %s nicht vorhanden
abort()
endif

(...)

content = ... strings
ret = seq.puts(strip$(content), fp.log)
ret = seq.puts(chr$(013), fp.log)

ret always is 0! content is given... I really don't get the problem...?

Thanks in advance,

NPRao
15th October 2013, 01:23
It is working properly and as expected. Refer to the Unix Operating System's file operations, buffers and streams - http://www.gnu.org/software/libc/manual/html_mono/libc.html#Flushing-Buffers
I noticed your code was missing the seq.close() call-

function long seq.close (long fp)
Description
This flushes the buffers associated with the specified file and closes the file. fp is the file pointer returned by seq.open() when the file was opened. Buffers allocated by the standard i/o system are also flushed and closed. These actions are performed automatically when the process exits.

stegro
15th October 2013, 10:29
thanks, the missing seq.close was the problem! Now the first run is right, just the second still doesn't work.

Han Brinkman
15th October 2013, 10:47
The second line is used to make sure you can read it in windows mode too?

If than try open the file with seq.open("....", "at")

According to the manual:

The line separator(s) for text-files are different on Windows NT and UNIX systems. CRLF on the former; LF only on the latter. In addition, a Windows NT text file can include an EOF-character (^Z) that indicates the end of the file. This character should not be returned to a program reading the file.

So, you must specify the "t" option when reading from or writing to a text file on Windows NT systems (for example, "at+".) This ensures that line separators and EOF characters are handled correctly. Never use the "t" option when opening a binary file; on Windows NT systems this will corrupt the file data. The "t" option has no effect on UNIX systems.

NPRao
15th October 2013, 21:06
thanks, the missing seq.close was the problem! Now the first run is right, just the second still doesn't work.
fp.log = seq.open (trim$(f.log.path)&trim$(tmp.log), "a")
if fp.log <= 0 then
mess(...., 1, tmp.log)
|Datei %s nicht vorhanden
abort()
endif

Post your complete code for others to review & help out, one cannot guess how is your code is working.
If you are ending the program abnormally (like the abort statement) and not calling the seq.close() to flush out to disk-write then you will have missing information in the file.