LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unbuffered stdout (https://www.linuxquestions.org/questions/linux-newbie-8/unbuffered-stdout-807782/)

sohumsin 05-14-2010 04:58 AM

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?

catkin 05-14-2010 05:04 AM

Quote:

Originally Posted by sohumsin (Post 3968120)
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


sohumsin 05-15-2010 02:18 AM

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.

catkin 05-15-2010 02:40 AM

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.

sohumsin 05-15-2010 09:46 AM

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.


All times are GMT -5. The time now is 09:45 PM.