Solved

Function to execute applications

Posted on 1998-07-24
13
210 Views
Last Modified: 2010-04-02
Hi everyone,

I need to write an application to run a list of other applications. May I know if anybody is aware of a win32 api or any C functions which can allow me to execute an application and then wait for it to complete before returning the control to my main application(to carry on with the other applications. If there is, how can I use it?


Thank You
Yinteo
0
Comment
Question by:Yinteo
[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
13 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1168526
#include <stdlib.h>
int system (const char *string);
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168527
ozo forgot to mention you pass a strng with the path and name of the executable you want to run as a parameter to this command.  Like system("C:\TEST\MYAPP.EXE");
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168528
You also might want to consider the spawn() functions (there is no "spawn" function there are about 10 of them that begin with "spawn" and have 1 or 2 letters at the end.)  These functions allow you to run a process and to specify its environment and parameters in a variety of ways.  With these functions you can  a mode of _P_WAIT to have your process wait until the other process finishes befure spawn returns.  Or you can specify _P_NOWAIT to have spawn return as soon as the other process starts.
0
Industry Leaders: 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 8

Expert Comment

by:trestan
ID: 1168529
There are several ways to run a program. Besides the system and spawn, there are still exec and createprocess. You can see the online help to find which one is most fit for youe need.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168530
And ShellExecute() as well.
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1168531
Ha!  at last, a chance to pick fault with nietod's Godlike, instant, and invariably correct answers  :)  !  ("C:\\TEST\\MAYAPP.EXE")


0
 

Accepted Solution

by:
vanille earned 200 total points
ID: 1168532
You can also use the CreateProcess function, then wait a "infinite" time with the waitforsingleobject...

Or better, do the same as before and create a timer (for the maximum time you want to wait in case of the process never end...) then wait with the waitformultipleobjects...

But I agree, it's a little more complicated that the spawn() function...

Good luck...
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168533
warmcat, that is still wrong.  the application name is "myapp" not "mayapp"!  :-)
0
 
LVL 8

Expert Comment

by:trestan
ID: 1168534
Why are sticking the typing errors...
Do you think vanille should post his comments as an answer? All of us have been polite to each other for so long time. Each of us has given meaningful advices.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168535
agreed.  Ozo was here first and gave a solution that should work.  But it will be up to Yinteo to decide who gets the points.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1168536
Or share the points by post other questions with smaller points indicating to whom. Reject this answer and wait 21 days then get the 200 back.
0
 

Author Comment

by:Yinteo
ID: 1168537
Thanks!
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168538
Yinteo you graded vanille's answer.  Is that really expert you felt contribute the most?  that answer had already been provided by trestan and I suspect it is not the one you want anyways.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SNMP error No Such Object available on this agent at this OID 3 373
What is sub-make ? 2 88
Finding Divisors 5 38
what type of pointer is this pointer? 3 24
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
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.

733 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