Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:02:00+00:00 2026-05-16T21:02:00+00:00

The following C file gives a bogus result when NUL is piped to it:

  • 0

The following C file gives a bogus result when NUL is piped to it:

int main()
{
  printf("_isatty = %d\n", _isatty(0));
}

the result is:

C:\Users\Edward\Dev\nulltest> test.exe < NUL
_isatty = 64

I’m pretty sure NUL (aka /dev/null) is not a terminal device! So I need to detect in another way whether or not the file descriptor corresponds to NUL. The number doesn’t have any specific meaning; I see it when I actually do have a terminal attached.

What should I do? This question suggests using a sketchy undocumented function to get the underlying name, presumably comparing it to NUL, but that feels less than ideal to me. Is there a better way?

P.S. This would help solve this GHC bug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:02:00+00:00Added an answer on May 16, 2026 at 9:02 pm

    From msdn:

    _isatty returns a nonzero value if the descriptor is associated with a
    character device. Otherwise, _isatty
    returns 0.

    NUL is like /dev/null on Unix, it’s a char device.

    Note that on Linux, isatty is different:

    The isatty() function tests whether fd
    is an open file descriptor referring
    to a terminal.

    What you can do is try to compare STDIN_FILENO (0) with ${cwd}/NUL (using stat or stat).

    Update:

    int ret = GetFileType(GetStdHandle(STD_INPUT_HANDLE));
    

    It will return FILE_TYPE_CHAR for NUL or tty.

    See GetFileType documentation for other values. You can detect files/char device/pipes.

    Update Final:

    Use GetConsoleMode for input and GetConsoleScreenBufferInfo for output.

    CONSOLE_SCREEN_BUFFER_INFO sbi;
    DWORD mode;
    if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode))
       fprintf(stderr, "not console\n");
    else
       fprintf(stderr, "console\n");
    if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi))
       fprintf(stderr, "not console\n");
    else
      fprintf(stderr, "console\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling a file glassShader.vert from the following method and it gives me
Accessing following html directly from file system gives me the correct duration. <video src=multimedia/bbb400p.ogv
I am writing a small test program that gives the following xml file as
I have following Html file with javascript. This gives me error that testCircle is
I have the following file: C:\Users\Jan\Documents\Visual Studio 2010\Projects\AzureTests\Build\82df3c44-0482-47a7-a5d8-9b39a79cf359.cskpg\WebRole1_778722b2-eb95-476d-af6a-917f269a0814.cssx\39e5cb39-cd18-4e1a-9c25-72bd1ad41b49.csman I can open this file fine
Given the following preview of my JSP file in my project : <%@ page
Given the following xml: <!-- file.xml --> <video> <original_spoken_locale>en-US</original_spoken_locale> <another_tag>somevalue</another_tag> </video> What would be
Given I have two File objects I can think of the following implementation: public
Given the following code (it's supposed to write helloworld in a helloworld file, and
Given the following: >>> from lxml import etree >>> contents=open('file.xml').read() >>> node=etree.fromstring(contents) How would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.