Repository navigation
Open Cons
Home › File I/O Functions › Open Cons
Opens standard input or output on a file number, to use like a file.
Open Cons As [#]filenumber
Open Cons For Input As [#]filenumber
Open Cons For Output As [#]filenumberfilenumber
Open Cons opens the console's stdin or stdout streams for reading or writing. A file number is bound to the stream, which is used in subsequent file operations, such as Input #. An available file number can be retrieved with FreeFile.
The Input file mode opens the stdin stream for reading file operations, such as Line Input #, while the Output file mode opens the stdout stream for writing file operations, such as Print #. The Output file mode is the default if not specified.
The stdin and stdout streams are the ones used when the calling process' input or output is redirected (piped) by OS commands, or when it is opened with Open Pipe.
To open both the stdin and stdout streams for file operations, a process must use multiple file numbers.
The normal screen commands, such as Color and Locate, do not work in this mode, because they do not accept a file number.
The Tab keyword, regardless of the given column number, is always interpreted as a simple comma (,) (next output will take place at the next 14 column boundary).
The error code returned by Open Cons can be checked using Err in the next line. The function version of Open Cons returns directly the error code as a 32 bit Long.
Warning: Presently, Open Cons does not work as described above. Without any file mode specifier, a runtime error 1 (illegal function call) occurs. With the Input file mode specifier, the only input mode is well supported. But with the Output file mode specifier, input and output modes are simultaneously supported.
Runtime errors:
Open Cons throws one of the following runtime errors:
(1) Illegal function call
In the first usage, Open Cons() returns a 32 bit Long: a zero (0) on success and a non-zero error code otherwise.
result = Open Cons( [For {Input|Output}[,]] As filenumber )(or using the QB-like syntax,)Open Cons [For {Input|Output}] As filenumber
- In QB the syntax was
OPEN "CON:" FOR INPUT|OUTPUT AS [#] filenumber
Dim a As String
Open Cons For Input As #1
Open Cons For Output As #2
Print #2,"Please write something and press ENTER"
Line Input #1,a
Print #2, "You wrote : ";a
Close
SleepCategory: File I/O Functions
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing