• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 752
  • Last Modified:

How can I pipe xevent viewer (xev) output to file completely?

I am using xev to note down all pressed key events but unfortunately after pipeline output to file , I always found last few presses keys missing...

I am using like

xev -id 0x3200020 >testout

I typed sentence --> full sentence
here in xev output last two alphabet 'c' and 'e' are missing from pipeline
xev-output
0
saini_er
Asked:
saini_er
  • 6
  • 4
  • 3
4 Solutions
 
Duncan RoeSoftware DeveloperCommented:
You mean send the output to a file?

xev > file
0
 
woolmilkporcCommented:

Hi,
this seems to be a consequence of stdout buffering.
As I believe, the only solution is to wait for the timeout or to stop xev gracefully.
 
wmp
0
 
Duncan RoeSoftware DeveloperCommented:
Oh I see the problem. When xev outputs to a file, it buffers file system blocks. For some reason, the last block is not flushed on SIGTERM or SIGINT.
You have to fool xev into being line-buffered. One way to do that is to use the "screen" command. Basically, if you type "screen -L" then you get a windo the contents of which are logged to a file called screenlog.0. As far as I can tell. this file is either updated on a line by line basis or updated every few characters. Anyway, logging only stops when you exit the shell that screen started for you, so you certainly catch all the xev output. "man screen" for more information.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
saini_erAuthor Commented:
I am using xev as integration im my code..I am already opening child process for that .I can't open new window with screen
0
 
woolmilkporcCommented:
Hi,

so, in your child process, do you see a chance to terminate xev gracefully in certain intervals (and then start it anew) to give its stdout the chance to get fflushed?

wmp

0
 
Duncan RoeSoftware DeveloperCommented:
I think the problem with xev is that is has no means of graceful termination. Even a click on the close button results in a series of reported events rather than an actual close. It doesn't appear to have any signal handlers, so any termination by signal will lose buffered output. The manual page says "it is essentially a debugging and development tool, and  should  not be needed in normal usage".
Seeing you are running it from a C program, there is actually a mechanism you could use to get xev to run line-buffered. You could open a pty and cause xev to run in that. Personally I haven't programmed a pty myself, but you could check the source of, debug or strace a utility that uses one such as expect. Xterm also uses a pty, but debugging that might be harder because of all he X traffic - also much harder to build a debuggable executable than to build expect.
0
 
saini_erAuthor Commented:
Basically , I am using perl program to execute xev for particular terminal window and then I am using `killall -9 xev` to terminate program..My perl program is interactive program which requires user input and  I am integrating xev to  capture all user activity on keyboard.....So I am looking for some good procedure which can flush the buffer of xev before it terminated the program  
0
 
saini_erAuthor Commented:
Hi folks
I would like to thank everyone for thier suggestion.Finally I came up with couple  of ideas to resolve this problem for which I need your input

OPTION1-> Is there any way that I can execute 'Returnk key' escape sequence from perl program. If We can execute retun key from perl program , then I can have changes in my code to ignore last return key.

OPTION2-> Is there any switch cases available in Perl like c where I can ask user to press return key to exit program


0
 
woolmilkporcCommented:
The problem is that you terminate it with 'kill -9' which leaves no chance to xev to flush its buffer!

0
 
saini_erAuthor Commented:
No I have tested this already..basically If I press two return key in the end of program with sleep(3) , it clears the buffer and I am getting my all keys.

I just want some procedure using escape sequences that my program with press return key two times
0
 
saini_erAuthor Commented:
I am using killall xev and not the forceful -9 option.sorry for confusion
0
 
Duncan RoeSoftware DeveloperCommented:
It doesn't matter which signal you use - unless xev catches that signal you will lose buffered output.
If you can build xev from source, you could insert the line:

setvbuf(stdout, NULL, _IONBF,0);

as the first line of main().
This inhibits all file system buffering.
0
 
saini_erAuthor Commented:
I got it working using sendkey.Thanks everyone for help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now