?
Solved

Using system function to run xview

Posted on 2004-04-24
7
Medium Priority
?
413 Views
Last Modified: 2006-11-17
I am writing C++ code (Linux) to display an image file using xview.  After the image is displayed for 10 seconds, how do I go about displaying the next file considering that I cannot launch xview again unless I close out the original display?

I tried this:

system("xview imageFile.pbm");
sleep(10);
system("xview imageFile2.pbm");

The only way I can shut down the application if I do a CTRL-C.  How can I capture those keystrokes and use it within the system function?  The only other way, which I was hoping I wouldn't have to do is use the system function to write out the process ids to a file then read that file and get the process id that corresponds to the xview.
0
Comment
Question by:jewee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 10908893
You'd use 'fork()' and 'exec()' for that, e.g.

while ( true) {

    char* image = "imageFile.pbm";
    pid_t pid;

    pid = fork ();

    if ( 0 == pid) { // child process, spawn xview

        execl ( "xview", "xview", image);

    } else { // main process, wait 10s, then kill xview and restart it again

        sleep ( 10);
        kill ( pid, SIGKILL);
    }
}
0
 

Author Comment

by:jewee
ID: 10909059
What header file do I need to include?
0
 
LVL 86

Expert Comment

by:jkr
ID: 10909088
You'll need

    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 10909092
BTW, see also http://www.ecst.csuchico.edu/~beej/guide/ipc/fork.html ("A fork() Primer")
0
 

Author Comment

by:jewee
ID: 10909752
Thank you for your help!  I tried your code and noticed that the execl command doesn't work.  XView does not execute.
0
 

Author Comment

by:jewee
ID: 10910006
I tried entering the path of xview but it said "image not found".  For the image, I included the path but it still didn't work.

I noticed that if I use the same code you provided me, but instead of using execl, I used system, then incremented the pid after, it worked but would only launch xview once.
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 10910150
>>and noticed that the execl command doesn't work.

My fault - if should be

       execl ( "xview", "xview", image, NULL);

:-(


0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question