no_redir.c

来自「文件名:c语言深入学习必备参考例子 很多经典的c例子:高级的宏定义」· C语言 代码 · 共 28 行

C
28
字号
#include <stdio.h>
#include <dos.h>

void main (void)
  {
     union REGS inregs, outregs;

     // check the stdin handle first
     inregs.x.ax = 0x4400;
     inregs.x.bx = 0;      // stdin is handle 0
     intdos (&inregs, &outregs);

     if ((outregs.x.dx & 1) && (outregs.x.dx & 128))
       fprintf (stderr, "stdin has not been redirected\n");
     else
       fprintf (stderr, "stdin is redirected\n");                      

     // Now check stdout
     inregs.x.ax = 0x4400;
     inregs.x.bx = 1;      // stdout is handle 1
     intdos (&inregs, &outregs);

     if ((outregs.x.dx & 2) && (outregs.x.dx & 128))
       fprintf (stderr, "stdout has not been redirected\n");
     else
       fprintf (stderr, "stdout is redirected\n");                      
  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?