Repository navigation
Isredirected
Home › Operating System Functions › IsRedirected
Returns non-zero if standard output, or input if asked, is redirected to a file.
Declare Function IsRedirected ( ByVal is_input As Long = 0 ) As Longis_input
IsRedirected checks whether stdin or stdout is redirected to a file, instead of being connected to the console/terminal as usual.
If is_input is equal to non-zero (-1), IsRedirected checks stdin.
If is_input is equal to zero (0), IsRedirected checks stdout.
Returns non-zero (-1) if stdin or stdout is redirected, otherwise returns zero (0).
#include "fbio.bi"
result = IsRedirected( is_input )- New to FreeBASIC.
'' A Windows based example, just for the use principle
'' Self-sufficient example, using his own .exe file as dummy input file for stdin redirection
#include "fbio.bi"
'' Quotation marks wrapping for compatibility with spaces in path name
Dim As String pathExe = """" & ExePath & """"
Dim As String fileExe = Mid(Command(0), InStrRev(Command(0), "\") + 1)
Dim As String redirection = " < """ & Command(0)
If LCase(Right(Command(0), 4)) = ".exe" Then
redirection &= """"
Else
redirection &= ".exe"""
End If
If Command() = "" Then '' First process without stdin redirection
'' Check stdin redirection
Print "First process without stdin redirection: IsRedirected(-1) = "; IsRedirected(-1)
'' Creation of asynchronous second process with stdin redirected from file.exe
Shell("start /d " & pathExe & " /b " & fileExe & redirection & " secondprocess")
'' Waiting for termination of asynchronous second process
Sleep
ElseIf Command() = "secondprocess" Then '' Second process with stdin redirection
'' Check stdin redirection
Print "Second process with stdin redirection : IsRedirected(-1) = "; IsRedirected(-1)
End IfCategory: Operating System Functions
Kind: function
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
- 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