views:

32

answers:

2

i'm trying to write a c code which opens the xeyes application and then those eyes keep changing its color constantly for a particular eriod of time..

i tried to achieve this by executing xeyes with one center color, adding a delay of 3 seconds, killing the process, and opening xeyes with another center colour and so on inside a loop.

on execution of this code however, the first xeyes process does not get killed and the following processes do not execute.

is there a better way of doing this?

+1  A: 

the reason for this is that you are using the system() command, which waits until xeyes closes. This never happens, so your code never executes past your first system command.

You can find out more information about the functions you are using by typing

man system

on the command line.

Rannick
BTW, i was only able to determine this by looking at your previous requests. since you seem to be new, I will offer you my favorite website for C/C++ coding help:http://www.cppreference.com
Rannick
Also, if you don't know, you can use the '. If you're trying to learn C, you may want to stick with simple text i/o or find a graphics library until you become comfortable with the language. If your goal is to make multi-colored xeyes, then blaze ahead! You are also getting experience with making system calls, which is usually considered a next-level topic!
Rannick
yes you're right. i couldn't find an command that can close xeyes. kill doesn't do the trick. in fact no command would work as the terminal loses control and waits for the xeyes to close.could u suggest me another approach to the bigger problem, that is to to change the colours?
moonpie187
Is this for school?
Rannick
Don't forget to mark this as the answer and give me a point. Are you a freshman, then?
Rannick
Why not just download the xeyes source and modify it to change the colors? It is open source after all...
alanc
alanc has a point... I think this makes a lot more sense from the place of an assignment from a teacher. Also, remember it is important for you to figure this stuff out on your own as much as possible before asking for help, as you are going to school specifically to be given problems like this to solve in order to make you a better programmer.
Rannick
A: 

I wouldn't use C to do this. You're better off using a shell script that launches xeyes in the background, sleeps, then kills it and launches it again. It's probably on the order of 5 lines.

That said, in order to get a timer to run while xeyes is running instead of after it closes, you need to fork off your xeyes process and run the timer that waits to kill it in a separate process. You might want to look into the functions from spawn.h.

Nathon