Solved

Running a separate Executable from the application

Posted on 2002-03-04
6
210 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

839 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