Thread: Launching an application within program runtime

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Launching an application within program runtime

    Hi, I am currently doing a program where I am receiving data via sockets and writing this data on a file (this is a video file). Now I need a mechanism so that when a certain number of packets have been received I launch a program automatically opening the file.
    I've already tried opening the file manually and after a certain amount of time video playback starts.

    The problem of course is not keeping track of the packets received but launching a program while execution of the program continues. Any suggestions and what concepts in particular do I need to learn? My current knowledge of C++ is standard (up to processing files, pointers etc. and basic usage of sockets)

    I'm programing in C++, using Linux OpenSuse 10.3.

    thanks in advance
    dav_mt

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    fork() & exec() [exec comes in a number of flavours].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    9
    Oki, i'm assuming that i need to learn some theory about threads.

    so basically it will boil down about having a thread receiving data on sockets, and a thread that will launch the video player right?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, fork() will create another instance of your application, exec() will run another program. You can't use threads if you want to run another program - you need to create a new process.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    9
    i managed to use the fork() function and till here we're good (thanks, looked at a quick tutorial and really saved me some time )

    i'm having some trouble using the exec() function

    Code:
    if (packetsrcvd == 850)
    	{
    	pid_t pID = vfork();
       	   if (pID == 0)
       	   {	
    		long counter = 0;
    		cout << "\nProcess created succesfully..." << endl;
    		execl("/bin/sh", "-r", "-t", "-l", "video_in.3gp", (char *) 0);
        	   }
    	}
    Finally i need to launch a video player to launch that 3gp file. So of course my code is currently incorrect since /bin/sh is expecting to execute an executable. So my next query is how will I be able to pass that video filename to an application.

    thanks

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, instead of /bin/sh, use whatever your video player is. And of course, you probably wouldn't pass -r etc to your player.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    9
    thanks for your help managed to make it work
    for future reference this is how it worked

    Code:
    execl("/*PATH TO VIDEO PLAYER*/", "-o", "/*VIDEO FILE*/", (char *) 0);
    where -o refers to opening the file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. syntax for launching another application?
    By Viper187 in forum C Programming
    Replies: 12
    Last Post: 09-03-2008, 08:06 PM
  2. Launching a program on startup
    By beanroaster in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2006, 01:21 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM