GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Aug-2004, 12:54
killer9012 killer9012 is offline
Member
 
Join Date: Mar 2004
Posts: 137
killer9012 is an unknown quantity at this point

Executing a program inside my program


What I want to do is making a program, that when i run it, it will launch a few programs for me, like kazaa, msn, ie, my internet connection, ect. I already have all these lnk files ready, im just not sure how to make my program execute them.

Thanks for any help.
  #2  
Old 05-Aug-2004, 14:05
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
The C standard library function system() will execute a program, defined by its argument. Note control won't return to the calling program until the called program is finished.

I am assuming you are using some version of Windows. Here is something that I threw together that launches a text editor, gnuplot, dev-c++, and two Microsoft Word windows on my system. (Windows XP). This program compiles and executes OK with Borland or Visual C++ compilers. For gnu c compilers (dev-cpp, etc.) use forward slashes in the path names.

CPP / C++ / C Code:
#include <stdlib.h>
#include <stdlib.h>
int main()
{
  system("start C:\\ftp\\vim\\vim61\\gvim.exe");
  system("start C:\\ftp\\gnuplot\\gp371w32\\wgnupl32.exe");
  system("start C:\\Dev-Cpp\\devcpp.exe");
  system("start f:\\\"Program Files\"\\\"Microsoft Office\"\\Office10\\WINWORD.EXE\"");
  system("start f:\\PROGRA~1\\MICROS~2\\Office10\\WINWORD.EXE");

  return 0;
}


Note that for directories having spaces in their names, there are two ways to indicate the path: put quotes around each directory in the path that has a space, or use the "8.3" (DOS) version of the name.

Here's how to find the "8.3" version of the name if your windows is installed on drive C:

Open a command window (run cmd.exe from the start window).
enter C:
enter cd \
enter dir /x

Then, among the stuff that comes out, you will see something like

08/02/2004 06:29 AM <DIR> PROGRA~1 Program Files

PROGRA~1 is the "8.3" version of the name of the "Program Files" directory.



Dave
Last edited by davekw7x : 05-Aug-2004 at 15:12.
  #3  
Old 06-Aug-2004, 12:27
killer9012 killer9012 is offline
Member
 
Join Date: Mar 2004
Posts: 137
killer9012 is an unknown quantity at this point
ok, now lets say in beetween program one and 2, i want the computer to stop for 30 seconds, then execute program 2, is their anyway to get the program to stop, then continue?

Also, lets say i ran internet explorer, and im reading emails or what not and dont want to be disturbed by other programs poping up over it, is their anyway the program can run them under the ie window?
  #4  
Old 06-Aug-2004, 14:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by killer9012
ok, now lets say in beetween program one and 2, i want the computer to stop for 30 seconds, then execute program 2, is their anyway to get the program to stop, then continue?


I don't have a c-program to do this (people using Borland command-line compilers can try sleep(), in <dos.h>, but its use is deprecated).

If you are running Windows XP, you can download the Windows Server 2003 Resource kit and use its sleep.exe function.

go to

http://www.microsoft.com/windowsserv...s/default.mspx

then select "Windows Server 2003 Resource Kit Tools" to download. You don't have to be running Windows Server 2003 to use the sleep.exe; it's OK for Windows xp.

Then, in your program you can say

CPP / C++ / C Code:

  system("start foo");
  system("sleep 10");
  system("start bar");


to cause a 10 second delay between "foo" and "bar" execution.

If you are on a Windows machine with gnu cywgin installed, it has a "sleep" function in its bin directory. Try this.

Dave
  #5  
Old 06-Aug-2004, 15:40
killer9012 killer9012 is offline
Member
 
Join Date: Mar 2004
Posts: 137
killer9012 is an unknown quantity at this point
um, so whats the start foo and bar?? Im new to this stuff so take it easy on me, lol.
  #6  
Old 06-Aug-2004, 17:09
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Sorry, it's kind of "inside" jargon to designate arbitrary programs, file names, etc. So instead of having to put real program names in there, or to use something unimaginative like XXX.exe or ABC.exe, we just use "foo" and "bar". You put whatever application program names that you are starting. You see this in lots of programming documentation and some books.

(The old military abbreviation FUBAR means F***** Up Beyond All Recognition; I think that's where someone got the idea for "foo" and "bar" some time ago.)


Dave
  #7  
Old 08-Aug-2004, 10:33
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I have always wondered about these 2 words too, so it's good to finally know where they came from. Thank you.
  #8  
Old 08-Aug-2004, 11:56
killer9012 killer9012 is offline
Member
 
Join Date: Mar 2004
Posts: 137
killer9012 is an unknown quantity at this point
so...

CPP / C++ / C Code:
#include <stdlib.h>
#include <stdlib.h>
int main()
{
  system("start C:\\ftp\\vim\\vim61\\gvim.exe");
  system("start (path) sleep.exe 10");
  system("start C:\\ftp\\gnuplot\\gp371w32\\wgnupl32.exe");
  system("start (path) sleep.exe 10");
  system("start C:\\Dev-Cpp\\devcpp.exe");
  system("start (path) sleep.exe 10");
  system("start f:\\\"Program Files\"\\\"Microsoft Office\"\\Office10\\WINWORD.EXE\"");
  system("start (path) sleep.exe 10");
  system("start f:\\PROGRA~1\\MICROS~2\\Office10\\WINWORD.EXE");

  return 0;
}

This correct?? Also is their anyway at the end of the program you can get it to start back at the start , like a restart of the program?

Also, if i wante to have it run to differnt inetnet explorers, and I wanted 1 to stay on top, and the other to be executed in the background, without poping up, could this be done?
  #9  
Old 08-Aug-2004, 12:37
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
This correct??

Not this one:

CPP / C++ / C Code:
 system("start (path) sleep.exe 10");

In general, the command

CPP / C++ / C Code:
  system("foo");

launches the command, foo, and waits for its completion before returning to the calling program

Fow Windows XP (and probably other Windows versions, too, but I don't have anything to test it with just now) the command.

CPP / C++ / C Code:
  system("start foo");

launches the command, foo, and returns immediately to the calling program.

You want the start for programs that are going to remain running, but not for the sleep().

Try the following (assuming you have the program sleep somewhere on your path, otherwise --- include the path in the argument):

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
  printf("Launching system(\"sleep 5\"):");
  system("sleep 5");
  printf("Returned from first call.\n");
  printf("Launching system(\"start sleep 5\"):");
  system("start sleep 5");
  printf("Returned from second call.\n");
  printf("Tttttthat\'s all, Folks!\n");
  return 0;
}

Then try it again with the system() commands in the other order.

Also, you can investigate the standard C function spawnl(). It includes an argument that can tell it whether to wait for completion or not.


Quote:
This correct?? Also is their anyway at the end of the program you can get it to start back at the start , like a restart of the program?

I'm not sure what you mean. You could, of course, make a loop

CPP / C++ / C Code:
  while(1) {
   .
   .
   .
  }

Quote:
Also, if i wante to have it run to differnt inetnet explorers, and I wanted 1 to stay on top, and the other to be executed in the background, without poping up, could this be done?

I don't know. Sorry.



Regards,

Dave
  #10  
Old 02-Sep-2004, 05:26
tigrjonok tigrjonok is offline
New Member
 
Join Date: Sep 2004
Location: Estonia
Posts: 1
tigrjonok is on a distinguished road

hmm


It's all OK but.

I have everything great. Programs are executing and so on(as I called them in file whatever'exe). BUT - the (whatever.exe)window doesn't close after executing external programs. a little help please? :$


hmm
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 21:06
Modify a C program ayoub C Programming Language 3 15-Mar-2004 12:34
error during program rjd72285 C++ Forum 0 11-Nov-2003 19:49
one program access another? dgoulston C++ Forum 1 07-Oct-2003 12:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.