Solved

Using system function to run xview

Posted on 2004-04-24
7
411 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
  • 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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