I have a device connected to the local network that sends a string to a specific port of a PC (connected to the same network) running Debian. On this PC I need to put that string to cursor position (for example, in an opened text editor).
I’m able to read the string from terminal with this command
nc -l -p 8888
but I can’t figure out a way to put that string to cursor position.
After testing I would like this to become a service that remains active in the background
Thanks to anyone who has suggestions.
EDIT:
As suggested by JoseLinares i tried to copy the netcat output to the clipboard with the command
nc -l -p 8888 | xclip
Then i tried to paste it to a text editor, but nothing happen.
Using echo command (echo "something" | xclip) it works.
Another strange thing, if send output to a file (nc -l -p 8888 > test) and open that file with "nano" editor i see the value, but if i try to open it with "cat", it is empty.
2
Answers
You can use xclip to save the output of nc in the clipboard:
Then use xdotool to simulate a click in the middle button of the mouse. This will lead to copy the clipboard content in the cursor position in most desktop managers:
2 is the id of the middle button
The
tcut cup
command, provided byncurses
allows you to move the terminal cursor to any position on the screen (0,0 being top-left).You can use it this way for example:
Here everything received by
nc
on port8888
is written to the terminal at the position (5,5).Note 1: There are several versions of
netcat
(nc
). Yours may not have the-k
switch (= don’t die after the first connection has ended).Note 2: You are mentioning a service. Services are generally not bound to a terminal, but you may open one (
man openvt
) or redirect the command above to an existing one (e.g.> /dev/tty1
)