LinuxQuestions.org
Help answer threads with 0 replies.
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 09-23-2004, 08:08 AM   #1
linj
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Rep: Reputation: 0
Substitue for read -t ?


I am running bash version 1.14.7(1) and I need to write a script to ask for user input from the console and wait x seconds and if there is no response in x seconds continue on. read –t would be great but this does not work in this version of bash and upgrading at this point is not an option. Can anyone tell me if there is another way to do this besides read –t?

Thanks!
 
Old 09-23-2004, 02:27 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Korn shell should be on your box.

Try ksh coprocesses:

asynchronous signal:
Code:
#!/bin/ksh
# file: asynch_signal.shl
sleep $1
kill -USR2 $PPID
exit
main script:
Code:
#!/bin/ksh
input=""
readit()
{
trap "return" USR2
asynch_signal.shl 10 |&
read input        
trap "" USR2 
echo "got here"
exit
}

echo "starting to read"
readit
echo "input = $input"

exit
 
Old 09-23-2004, 02:55 PM   #3
cracauer
Member
 
Registered: Jul 2004
Location: Boston, MA, USA
Distribution: FreeBSD, Debian/AMD64, Ubuntu/i386
Posts: 59

Rep: Reputation: 15
The only portable way to do that is to fork and have one brnach read and the other one kill the reading one after a sleep.
 
Old 09-23-2004, 03:19 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I think he wants a shell script method.

Your C or whatever program method is the best answer.
 
Old 09-23-2004, 08:59 PM   #5
linj
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Jim
I tried your code and am getting:

syntax error near unexpected token '&'
line 7: 'asynch_signal.shl 10 |&'

Yes I would like a shell script method if possible but I can do c++. However, I am a linux rookie and have not tried any c++ for linux yet but I am willing to try. What is the recommened compiler for linux?


Thanks a lot for the posts guys!
 
Old 09-23-2004, 09:23 PM   #6
cracauer
Member
 
Registered: Jul 2004
Location: Boston, MA, USA
Distribution: FreeBSD, Debian/AMD64, Ubuntu/i386
Posts: 59

Rep: Reputation: 15
Of course you can fork from the shellscript.

Too lazzy to do a real one but here's the basics:

#! /bin/sh
otherpid=$$
(
sleep 10
kill $otherpid
# take over from other script
)
otherpid=$!
read foo
kill $otherpid
 
  


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
Mounted read-write Fat32 partition suddenly becomes read-only?? hohead Linux - General 8 04-05-2007 12:17 PM
mozzla problems-can not read files online, can not read attachments sarajevo Linux - Software 1 09-20-2005 06:58 PM
Example share in smb.conf doesn't work - read/write vs read only kleptophobiac Linux - Networking 0 09-01-2004 07:14 PM
kernel panic unable to mount root (yes ive read/read other posts) dmx9595 Linux - General 4 01-17-2004 05:07 AM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM

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

All times are GMT -5. The time now is 08:12 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