Wiki source for KeyPgOpenCons


Show raw source

{{fbdoc item="title" value="OPEN CONS"}}----
Opens the console's standard input (//stdin//) or output (//stdout//) streams for use in file operations.

{{fbdoc item="syntax"}}##
**Open Cons** **As** [**#**]//filenumber//
**Open Cons** **For** [[KeyPgInputfilemode|Input]] **As** [**#**]//filenumber//
**Open Cons** **For** [[KeyPgOutput|Output]] **As** [**#**]//filenumber//
##
{{fbdoc item="usage"}}##
//result// = **Open Cons**( [**For** {**[[KeyPgInputfilemode|Input]]**|**[[KeyPgOutput|Output]]**}[,]] **As** //filenumber// )
##//(or using the QB-like syntax//,)##
**Open Cons** [**For** {**[[KeyPgInputfilemode|Input]]**|**[[KeyPgOutput|Output]]**}] **As** //filenumber//
##
{{fbdoc item="param"}}
##//filenumber//##
An available //file number// to bind to the //stdin// or //stdout// stream, which can be found with ##[[KeyPgFreefile|Freefile]]##.

{{fbdoc item="ret"}}
In the first usage, ##**Open Cons()**## returns a 32 bit ##[[KeyPgLong|Long]]##: a zero (0) on success and a non-zero error code otherwise.

{{fbdoc item="desc"}}
##**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 ##[[KeyPgInputPp|Input #]]##. An available //file number// can be retrieved with ##[[KeyPgFreefile|Freefile]]##.

The ##[[KeyPgInputfilemode|Input]]## //file mode// opens the //stdin// stream for reading file operations, such as ##[[KeyPgInputPp|Line Input #]]##, while the ##[[KeyPgOutput|Output]]## //file mode// opens the //stdout// stream for writing file operations, such as ##[[KeyPgPrintPp|Print #]]##. The ##[[KeyPgOutput|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 ##[[KeyPgOpenPipe|Open Pipe]]##.

To open both the //stdin// and //stdout// streams for file operations, a process must use multiple //file numbers//.

The error code returned by ##**Open Cons**## can be checked using ##[[KeyPgErr|Err]]## in the next line. The function version of ##**Open Cons**## returns directly the error code as a 32 bit ##[[KeyPgLong|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 ##[[KeyPgInputfilemode|Input]]## //file mode// specifier, the only input mode is well supported. But with the ##[[KeyPgOutput|Output]]## //file mode// specifier, input and output modes are simultaneously supported.

**Runtime errors:**
##**Open Cons**## throws one of the following [[ProPgErrorHandling|runtime errors]]:

//(##1##) Illegal function call//
- ##//filenumber//## was not free at the time. use ##[[KeyPgFreefile|Freefile]]## to ensure that ##//filenumber//## is free.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/fileio/opencons.bas"}}%%(freebasic)
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
Sleep
%%

{{fbdoc item="diff"}}
- In QB the syntax was ##OPEN "CON:" FOR INPUT|OUTPUT AS [#] //filenumber//##

{{fbdoc item="see"}}
- ##[[KeyPgOpen|Open]]##
- ##[[KeyPgOpenScrn|Open Scrn]]##
- ##[[KeyPgOpenErr|Open Err]]##
- ##[[KeyPgFreefile|FreeFile]]##

{{fbdoc item="back" value="CatPgFile|File I/O Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode