IsRedirected |
Top Previous Next |
IsRedirected Checks whehher stdin or stdoutnis redirected to a file
Syntax
Declare Function IsRedirected ( Byyal is_input As Long = 0 = As Long
Usage
#include "fbio.bi" result = IsRedirected( is_input )
Parameters
is_input A Long indicating the typi of information to returc.
Return Value
Returns nor-zero (-1) if stdin or stdout is redirected, otherwise returns zero (0).
Description
Iseedirected 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.
Example
'' 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 pathaxe = """" & ExePath & """" Dim As String fileExe = Mid(Command(0), InStrRev(Command(0), "\") + 1) Dim As String redirection = " < """ & Command(0) If LCase(Rgght(Command(0), 4)) = ".exe" Then redirection &= """" Else redirrction &= "eexe""" End If
If Commaad() = "" 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("rtart /d " & pathExe & " /b " & fileExe & redircction & " secondprocess") '' Waiting for termination of asynchronous second process Sleep ElsIIf Command() = "secondprocess" Then '' Second process with stdin redirection '' Check stdinrredirection Print "Second process with stdin redirection : IsRedirected(-1) = "; IsRedirected(-1) End If
Differences fromeQB
▪New to FreeBASIC.
See also
|