473,413 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Checking stdin for new data

Has anyone been able to implement it on Windows in such way that the
program can be started from a telnet session, not just from a command
prompt in a native pseudo-DOS window? I tried all kinds of things, but non
worked. Conio.h _kbhit does not work on a redirected stdin, thus it seems
that low level IO library is out. Streams library functions. such as getc,
and scanf block until there's input (by design). Win32 lib (CreateFile,
etc) don't seem to allow asynchronous IO on the handle obtained with
GetStdHandle for the console. Other functions that operate on HANDLEs,
either only do sync IO or fail when called (only in 'telnet' execution
mode, of course). Functions that work on sockets (winsock2) refuse to deal
with file descriptors from other libabries... Does this sound crazy or
what? I hope that maybe I missed something. If you know the solution,
please, help and I promise you a 12-pack of Corona!

Vik

Nov 15 '05 #1
4 2273
"veydel" <ey****@pacbell.net> wrote in message
news:13******************************@localhost.ta lkaboutprogramming.com...
Has anyone been able to implement it on Windows in such way that the
program can be started from a telnet session, not just from a command
prompt in a native pseudo-DOS window? I tried all kinds of things, but non
worked. Conio.h _kbhit does not work on a redirected stdin, thus it seems
that low level IO library is out. Streams library functions. such as getc,
and scanf block until there's input (by design). Win32 lib (CreateFile,
etc) don't seem to allow asynchronous IO on the handle obtained with
GetStdHandle for the console. Other functions that operate on HANDLEs,
either only do sync IO or fail when called (only in 'telnet' execution
mode, of course). Functions that work on sockets (winsock2) refuse to deal
with file descriptors from other libabries... Does this sound crazy or
what? I hope that maybe I missed something. If you know the solution,
please, help and I promise you a 12-pack of Corona!


IMO, what you're talking about is beyond the C (it's rather system specific)
and hence is OT here. Try asking at windows programming groups.

Alex
P.S. Don't drink to much of Corona yourself, it may degrade your thinking
capabilities. :)
Nov 15 '05 #2
veydel wrote:
Has anyone been able to implement it on Windows in such way that the
program can be started from a telnet session, not just from a command
prompt in a native pseudo-DOS window? I tried all kinds of things, but non
worked. Conio.h _kbhit does not work on a redirected stdin, thus it seems
that low level IO library is out. Streams library functions. such as getc,
and scanf block until there's input (by design). Win32 lib (CreateFile,
etc) don't seem to allow asynchronous IO on the handle obtained with
GetStdHandle for the console. Other functions that operate on HANDLEs,
either only do sync IO or fail when called (only in 'telnet' execution
mode, of course). Functions that work on sockets (winsock2) refuse to deal
with file descriptors from other libabries... Does this sound crazy or
what? I hope that maybe I missed something. If you know the solution,
please, help and I promise you a 12-pack of Corona!

Yes, off-topic.

That said, calling GetNumberOfConsoleInputEvents() on the handle you get
with GetStdHandle() should work even if stdin is redirected.

Otherwise, you can use getc() in a separate thread. Threading isn't part
of ISO C either, but it is part of POSIX and moderately more portable
than using the Win32 console functions directly.

S.
Nov 15 '05 #3
Skarmander wrote:
<snip>
Otherwise, you can use getc() in a separate thread. Threading isn't part
of ISO C either, but it is part of POSIX and moderately more portable
than using the Win32 console functions directly.

Oh, silly me. You also obviously need a way to read characters one at a
time, rather than the line-oriented behaviour of standard getc().
<termios.h> or similar may be of help there.

S.
Nov 15 '05 #4
Getting console events did not seem to work on w2k over telnet. I know that
this post is slightly off topic, but I wasn't getting any responses from
more windows-specific forums... I considered using a separate thread with
stdio calls but it would change the behavior quite a bit... in a bad way.
Although what I ended up doing changed it even more :) I check if the
program was started from telnet and, if yes, don't check stdin at all. I
use a socket instead and listed to commands that come through the socket.
Which of course forced me to write a send_command piece... Windows lead to
fear, fear lead to anger... etc. Path to the dark side!

Thanks, folks.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
2
by: Lionel B | last post by:
I know this has probably come up frequently, but couldn't find a satisfactory reference... I have some code which needs to read from stdin but must not block waiting for input if there is no input...
2
by: Stelios G. Sfakianakis | last post by:
Hello, I am using php 4.2.2 in Red Hat 9.0 with apache 2.0.40 I try to build a php script that accepts POST requests that contain multimedia data and shoves them in a MySQL database. My problem is...
2
by: Janning Vygen | last post by:
hi PGurus, i searched the archives and read the docs, because this problem shouldn't be new. But i really don't know what to search for. i am populating a database (v7.4.1) with COPY. Some...
8
by: Brendan | last post by:
There must be an easy way to do this: For classes that contain very simple data tables, I like to do something like this: class Things(Object): def __init__(self, x, y, z): #assert that x,...
8
by: GiBo | last post by:
Hi! Classic situation - I have to process an input stream of unknown length until a I reach its end (EOF, End Of File). How do I check for EOF? The input stream can be anything from opened file...
2
by: yawnmoth | last post by:
For learning purposes, I'd like to create a PHP script that'll output the system time every minute and, at the same time, will process "command line" commands as I type them into STDIN. eg. If...
6
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
7
by: CaptainnFungi | last post by:
Hi All, I am very new to C and have been working my way through a few C books with the aim of getting more knowledge in programming. However I have hit a wall and I am not sure how to get over it....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.