Solved

Using system function to run xview

Posted on 2004-04-24
7
409 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

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