LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2010, 05:58 AM   #1
sohumsin
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Rep: Reputation: 0
Smile unbuffered stdout


Hi everyone,

Normally,

>cat > temp
a
b
c
d
ctrl-d

the file is wrote after ctrl-d.

Is there any way to perform a write with a CR?
 
Old 05-14-2010, 06:04 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by sohumsin View Post
Is there any way to perform a write with a CR?
Assuming you want to flush the data entered so far when an empty line (carriage return only) is entered by the user then this should do it
Code:
buf=
while read
do
    if [[ $REPLY != '' ]]; then
        buf="$buf$REPLY"$'\n'
    else
        echo -n "$buf" >> tmp
        buf=
    fi
done
 
Old 05-15-2010, 03:18 AM   #3
sohumsin
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hi Catkin,

I tried to unbuffer the xev. so that I can grep every event with CR.

I hope there is some setting to made the stdout unbuffer.

Thanks any way.
 
Old 05-15-2010, 03:40 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Ah! This is a continuation of your Slow reponse >xev | grep keyPress thread. A good try but I don't think it will work because I theorise xev itself is doing the buffering; it probably checks where its stdout is going then, if it is a terminal, does not buffer it (or line buffers it) or, if it is to pipe or file, buffers it. If my theory is correct there are two options; modifying xev source (possible and an interesting exercise) or run xev with output to terminal and intercept the data. The bootlogd executable does something along those lines.
 
Old 05-15-2010, 10:46 AM   #5
sohumsin
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hi catkin,

I do not agree with you. xev alone will give you the problem the moment the result is is pass to stdout if you case is true. But it did not happened, the problem is the stdout | waiting for the EOL like a file that cause the delay.

In order to solve this, we can either make the stdout to accept CR or make the buffer size = 1 or smaller than the keypress event record size, which will help the response of the solution.


I hope some guru may highlight me how to achieve this. I had tried to write my own application to capture all the keypress but facing problem on ctrl, shift and alt key(windows also). I had tried to set the parameter of termio. No luck.

I had tried to search online and read some reference book in library hope to discover some thing for this little problem. Still Trying !!!! Let hope something will happened next few day.

Thanks anyway.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
buffered and unbuffered i/o netrak Linux - Newbie 2 09-18-2009 07:04 AM
How to redirect standard stdout to multi stdout ( Bash )? john.daker Programming 4 11-04-2008 12:20 AM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 03:36 AM
unbuffered stdin Mike Davies Linux - Software 1 03-03-2006 01:13 AM
unbuffered stdin mvt Programming 7 05-17-2004 10:40 PM


All times are GMT -5. The time now is 06:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration