Sending program a command through terminal/command line?

Hello,

I have a custom program that I am running under OpenSuse 11.1, gnome environment.

As part of the program, I have a quit function that cleanly exits the program whenever the ‘q’ key is hit. This program uses the opencv function “cvWaitKey()” to obtain a keyboard hit. The program’s window must be selected for this command to work.

My question is: is there a way for me to send a quit command through the terminal/command line to my program?

Ideally what I want to do is to set up a shell script that will run every minute to check for an alert (via the crontab). And if the alert is set then this script will send the quit command to the program.

I appreciate any advice to help with this. Thank you!

Hi
Replace your_prog with the appropriate name.


kill -SIGTERM `pidof your_prog`


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.12-0.7-default
up 1 day 8:33, 3 users, load average: 0.02, 0.04, 0.00
GPU GeForce 8600 GTS Silent - Driver Version: 195.36.31

Thanks for the reply.

But I would like a command that sends a ‘q’ to my custom program. This is because after the ‘q’ is received the program goes to a label that executes functions for memory deallocation before quitting.

What about putting code into your quit function? Normally, the kill causes the registered quit function of the program to execute so if there is clean-up to do it can shutdown safely.

I think if you look through the forum you’ll find a similar question a while back. There’s a command X utility to send an arbitrary X event to a specified window. An X event can be a keystroke, a mouse event, and various other windowing system events. Sorry, don’t have the link, just something at the back of my mind.

Thanks for the input guys, I’ll try making a function that will respond to the SIGTERM signal and see how it works out. (I believe this is signal handling from what I’ve read up so far - InformIT: C++ Reference Guide > Signal Processing . Do you know any other tutorial pages that would be helpful for doing this?)

I appreciate your prompt replies!