Error getting tags :
error 404Error getting tags :
error 404 write to file | revDocs | RunRev
Welcome Guest (Log in)
Product Edition
Version
write to file
Basics
Expander triangle
Type
Command
Syntax

write value to {file filePath | stdout} [at {start | EOF | end}]

Introduced
1.0
Environment
Desktop, Web and Server
Platform Support
MacOS,Mac OS X,Windows,Linux
Security
Disk
Summary
Places data in a file that has been opened with the open file command.
Examples

write "Testing, testing" to file "testfile"
write nextData to file theFile at 350 -- starts at char 350
write linefeed to stdout
write "ATZ" to file "modem:"

Additional Comments
Expander triangle

Use the write to file command to change the contents of a file.

Parameters:

The value is any expression that evaluates to a string.

The pathName specifies the name and location of the file you want to write to. It must be the same as the path you used with the open file command. The pathName is case-sensitive, even on platforms where file names are not case-sensitive.

If you specify the name of a serial port on Mac OS or Windows systems, Revolution writes to the specified port. The names of serial ports end in a colon (:).

The start specifies the character or byte position in the file where you want to begin writing. A positive number begins start characters after the beginning of the file; a negative number begins start characters before the end of the file.

If you specify either of the synonyms EOF or end, the write begins after the last character in the file.

If you don't specify a start, the write begins:

* at the position determined by the seek command, or

* if you haven't used the seek command, wherever the last read from file or write to file command to the file left off, or

* if you haven't accessed the file with read from file or write to file since it was opened, after the last character (if the file was opened in append mode) or at the first character (if the file was opened in any other mode).

Comments:

The file to write to must be opened first with the open file command, and the mode the file was opened in must be write, append, or update. If the file is not open or is open read-only, the result function is set to "File is not open for write.".

If the file was opened in write mode, the write to file command completely replaces the file contents from the start. For example, if the file originally contains "ABC", and you write "1" to it, after the write to file command is executed the file contains "1".

If the file was opened in update mode, if you write less data to the file than it already contains, the write to file command does not remove characters from it. For example, if the file originally contains "ABC", and you write "1" to it, after the write to file command is executed the file contains "1BC".

If the file was opened in append mode, the write begins at the end of the file.

Important! After writing, you must close the file with the close filecommand.

The write to stdout form writes to the standard output (on Unix systems). The standard output is always open, so you can write to it without first opening it.

Tip: As an alternative to the open file and write to filecommands, you can also use the URLkeyword with the putcommand to change the contents of a file.

User Comments
Expander triangle
User thumbnail
benr_mc@cogapp.com
StarStarStarStarStar
Apr 27, 2009
Note that, while as mentioned above on Unix systems (including Mac OS X) standard output is always open, on Windows it is not. Normally on Windows the result of a write ... to stdout will be an error "error writing file" unless the standard output was opened. AFAICT, the only way to open it is to launch the Rev app from the command line with the output being piped to another command or directed to a file For example, if you launch your app like this

myapp.exe > output.txt


then a file 'output.txt' will be created (or deleted and recreated), and anything that the app writes to stdout will go to this file. (Using ">>" instead of ">" will append to output.txt rather than overwriting it.) Similarly "2>" directs the stderr to a file, so you could use this to capture both:

myapp.exe > output.txt 2> error.txt