Operating System - HP-UX
1829556 Members
1822 Online
109992 Solutions
New Discussion

flush input buffer of terminal

 
YLTan
Frequent Advisor

flush input buffer of terminal


I have a scripts that execute a cmd at background using &. How do I flush the input buffer thereafter
tyl
11 REPLIES 11
generic_1
Respected Contributor

Re: flush input buffer of terminal

TCSAFLUSH
Is that what you are looking for?
YLTan
Frequent Advisor

Re: flush input buffer of terminal

how do i use this TCSAFLUSH?
tyl
generic_1
Respected Contributor

Re: flush input buffer of terminal

It is part of C.
You will probably have to write a short program in C to call it and put the program in your path.
generic_1
Respected Contributor

Re: flush input buffer of terminal

You will see many references to it on google.
YLTan
Frequent Advisor

Re: flush input buffer of terminal


Is there a solution for this in ksh shell? My script is written in ksh scripting.
tyl
A. Clay Stephenson
Acclaimed Contributor

Re: flush input buffer of terminal

No, but here's an attached C program. It's intentionally done in K&R C so that even then Bundled C compiler can handle.

Compile like this:
cc flushinput.c -o flushinput

Use it like this:
flushinput
If it ain't broke, I can fix that.
generic_1
Respected Contributor

Re: flush input buffer of terminal

reboot :)
Kiyoshi Miyake
Frequent Advisor

Re: flush input buffer of terminal

Hi,

What cmd do you want to flush?
Please show example.

Some command do block buffering when it runs without terminal.(e.g. STDOUT is PIPE)

so, check cmd option that no buffering.

thx.
YLTan
Frequent Advisor

Re: flush input buffer of terminal


i have a legacy scripts which have this in the begining of the file. then some where in the middle of the file. it uses eval cmd to run another scripts. And in that scripts it call a program with &

the problm i have is that the scripts can return normally back. It go into some endless loop. when I take out & , it hang the screen. So i suspect it could be due to input buffer still holding some cmd causing the scripts to run infinitely.

trap 'maintain_configlist; return' 2 3 4 5 6 7 8 15
....
....

eval .
...
...

another scripts content:
/somedir/someprog/prog &

I can't paste it here cause it call multiple other file.
tyl
Kiyoshi Miyake
Frequent Advisor

Re: flush input buffer of terminal

try ...

eval . < /dev/null

or

somedir/someprog/prog < /dev/null &

or
insert "set -x" into head of prog or some scripts.
this option show command log.

thx.
A. Clay Stephenson
Acclaimed Contributor

Re: flush input buffer of terminal

It appears that you really asked the wrong question. I doubt that your problem has anything to do with flushing an input buffer but rather that your background command is actually expecting a tty device for input. You probably need to surround some commands in your backgrounded scripts with
if [ -t 0 ]
then
echo "Stdin is a tty device"
else
echo "Not"
fi

this will let your script bypass sections of code when it is not in an interactive environment. You also need to be careful when you have more than one process reading from a common file. The input will be interleaved among the competing processes and chaos is assured.
If it ain't broke, I can fix that.