LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2012, 08:21 PM   #1
rmknox
Member
 
Registered: May 2010
Posts: 354

Rep: Reputation: 34
how would i do it on windows - c program


I have a c program i run at the command line.

I would like to compile it on a windows system to run on windows so I can share it with one of my kids - one of those windows user people.

I put up a prompt and then wait till either the user answers or it times out.

I do that using a POSIX feature - a call to "select" .

I understand that POSIX features are not typically supported on windows.

Can someone familiar with c and windows - command line - not graphical - tell me how to wait either for input on stdin or till n seconds pass, using a feature that windows supports ?

Thanks

Dick
 
Old 06-14-2012, 09:32 AM   #2
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Windows (Visual Studio) supports select, I use it all the time. Porting code from Linux over to Windows is fairly easy. Porting from Windows to Linux can be tougher if the program is coded using Windows-isms (Functions that are specific to the Windows platform and may or may not have corresponding Linux functionality). If you stick to the Linux APIs, your should be okay when porting the code over to Windows.

Also, you could get the cygwin IDE instead of using Visual Studio.

Multiple ways to do what you are asking.
 
Old 06-14-2012, 07:14 PM   #3
rmknox
Member
 
Registered: May 2010
Posts: 354

Original Poster
Rep: Reputation: 34
rstewart
i just tried it and did not succeed - I downloaded the free 30 day version of visual

heres what i have in linux
#include <unistd.h>
...
#include <sys/time.h>
...
return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
&set, NULL, NULL,
&timeout));
...
it complained about the three lines above + and others defined in the h files

on linux it is a c program - i note that in visual everything is c++
maybe i need different header definitions?

any wisdom you can share is appreciated

Dick
 
Old 06-15-2012, 08:44 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Windows defines some POSIX functions, but not all and they are often in different header files. It does have select, but I'm pretty sure it's only for sockets; you can't use it to test stdin.

You may be able to use WaitForSingleObject, although there is a comment on that page:
Quote:
Originally Posted by Medinoc
Make sure to disable the ENABLE_LINE_INPUT console mode before waiting on a console input buffer object.

Regardless of the mode, console input buffer objects are signaled as soon as a character is typed, while the reading functions will block until the line is finished, voiding the purpose of a dedicated, time-limited wait function.
 
Old 06-15-2012, 09:33 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Anyone else trying to help in this thread may wish to know that a big part of the relevant info is in the OP's related thread. See
http://www.linuxquestions.org/questi...7/#post4704019
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wine installed a program onto my windows partition, Windows BSOD on boot. DJGCrusader Linux - Enterprise 9 08-14-2009 08:25 AM
A program for FC4 to communicate with a Windows Hyperterminal Program at other end vhasun Linux - Software 2 05-19-2006 02:54 PM
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Running a windows program from windows partition, on linux, possible? Kriptis Linux - Newbie 4 01-18-2005 10:52 PM
Best Windows Program Mannyakatheman General 21 12-24-2003 04:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration