Solved

Running a separate Executable from the application

Posted on 2002-03-04
6
206 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
Comment Utility
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
Comment Utility
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
i feel best to use is

shell_execute();
 pass the paramater which ever file u want to execute
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:Axter
Comment Utility
>>shell_execute();
You mean ShellExecute...???
0
 

Expert Comment

by:surenpv
Comment Utility
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
Comment Utility
Thanks.  I will give it a try.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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 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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now