Skip to content

ISREDIRECTED


检查 stdin 或 stdout 是否被重定向到文件

语法

declare function IsRedirected ( byval is_input as long = 0 ) as long

用法

#include "fbio.bi"
result = IsRedirected( is_input )

参数

is_input

指定要返回的信息类型的 long 值。

返回值

若 stdin 或 stdout 已被重定向,返回非零值(-1);否则返回零(0)。

说明

IsRedirected 检查 stdin 或 stdout 是否被重定向到文件,而非像通常那样连接到控制台/终端。

is_input 为非零值(-1),IsRedirected 检查 stdin。

is_input 为零(0),IsRedirected 检查 stdout。

示例

vb
'' 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 If

与 QB 的差异

  • FreeBASIC 新增。

另请参阅

  • Reset(streamno)

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系