Find the answer to your Linux question:
Results 1 to 7 of 7
Hi group, I'm looking for a way to check if any data is waiting on stdin. I know I can use Select under linux but that will not work with ...
  1. #1
    Just Joined!
    Join Date
    May 2005
    Posts
    15

    Checking stdin for new data

    Hi group,

    I'm looking for a way to check if any data is waiting on stdin.
    I know I can use Select under linux but that will not work with
    Windozes and I want to be able to use the same code for both.
    I could use getc and then ungetc but that is sloppy.

    Any ideas?

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    may we ask what language?
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    Hi,
    How about setting up buffers and then you can read write manipulate them as you wish. Use a general buffer setup in C etc so that it is portable.

    wowbag1

  4. #4
    Just Joined!
    Join Date
    May 2005
    Posts
    15

    I am using C

    Quote Originally Posted by meton_magis View Post
    may we ask what language?
    I am using standard C.

  5. #5
    Just Joined!
    Join Date
    May 2005
    Posts
    15
    Quote Originally Posted by wowbag1 View Post
    Hi,
    How about setting up buffers and then you can read write manipulate them as you wish. Use a general buffer setup in C etc so that it is portable.

    wowbag1
    That is what I am doing but it gets a little messy. The problem is that I am waiting for input in subroutine and the input can be either a numerical string for the length of the data or the data itself. It work well but the caller may send more data then they sead they were. in this case I need to filter out the extra data, reading the steam until I get what looks like a valid length ( "nn\n") or a quit command ("q\n").

    It would just be clearer to have a way of checking the input.

  6. #6
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I know nothing about programming under Windows, but:
    select Function (Windows)

    select() is probably the best option for this if you can get it working, since it's explicit purpose is to tell you when a stream is ready.
    DISTRO=Arch
    Registered Linux User #388732

  7. #7
    Just Joined!
    Join Date
    May 2005
    Posts
    15
    Quote Originally Posted by Cabhan View Post
    I know nothing about programming under Windows, but:
    select Function (Windows)

    select() is probably the best option for this if you can get it working, since it's explicit purpose is to tell you when a stream is ready.
    Windozes only supports Select for scokets not other file types.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...