Solved

Function to execute applications

Posted on 1998-07-24
13
208 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
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

770 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