Solved

Running a separate Executable from the application

Posted on 2002-03-04
6
213 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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

636 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