Solved

Running a separate Executable from the application

Posted on 2002-03-04
6
211 Views
Last Modified: 2010-04-01
I am needing to run one executable from within another application.  For instance, assuming that I have a basic "Hello World" application, how would I open it from a separate application and print "Hello World" to the screen.  Basically, I am needing to know how to run command line commands within my code.  

// very simple example code
void main()
{
   // run "Hello World" application here
   // from the command line, it would look like
   // c:/hello.exe

   // do more processing...
}
0
Comment
Question by:guile1
[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
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6840554
The easiest way would be using "system()".

/* SYSTEM.C: This program uses
 * system to TYPE its source file.
 */

#include <process.h>

void main( void )
{
   system( "type system.c" );
}


Output

/* SYSTEM.C: This program uses
 * system to TYPE its source file.
 */
#include <process.h>
void main( void )
{
   system( "type system.c" );
}


In your case, just change it to read

   system( "hello.exe" );

You might have to provide a path, though...
0
 
LVL 30

Expert Comment

by:Axter
ID: 6840669
0
 
LVL 4

Expert Comment

by:havman56
ID: 6840932
i feel best to use is

shell_execute();
 pass the paramater which ever file u want to execute
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 30

Expert Comment

by:Axter
ID: 6841154
>>shell_execute();
You mean ShellExecute...???
0
 

Expert Comment

by:surenpv
ID: 6841190
system() call is the easiest to call an application. If u need more control over the way the new application is started you can use ShellExcuteEx() method. You can set different options like how the applcation should be started ( minimized, maximized etc. ) by filling the SHELLEXECUTEINFO structure and passing it to the ShellExecuteEx method.

Cheers !!!
surenpv
0
 

Author Comment

by:guile1
ID: 6841463
Thanks.  I will give it a try.
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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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