TO CALL OTHER PROGRAMS FROM WITHIN OTHER PROGRAMS-

Just include the standard c header file cstdlib (no .h!!).
You can now use the function system( :eek: ). It takes only one parameter- the name of the program you want to call! Here is an example

#include <iostream>
#include <cstdlib> // You need this to call the system() function
using namespace std;

int main()
{
char prog[100];

cout << "Enter the program you want to call:\t"; // Prompt for a program and run it.
cin.getline(prog);

system(prog);

return 0;
}

Recommended Answers

All 10 Replies

What about passing command line arguments to a program?

You enter it with the program, e.g system("program argument");
You can also use DOS commands in this way.

hi,i'm new here...would u tell me something about this web..and i need ur advise about c++..because i'm in !@$#$%$

@ sinB -> yeah silly me! it was late and i was tired... :)
@ marilyn -> try the main c/c++ forum and start a thread if you have a programming problem

Hello,

Welcome to DaniWeb. For the best help, it is best to find the proper forum for your subject (C++) and then post some code that you are having troubles with, and the community will look at it and help you out. They will ask you to show your work... so no posting of the homework assignment and asking for an answer.

If you do not know the code, post psuedo code:

Begin
Ask for name
Ask for phone number
Store record
Print it out
Write to File
End

And then we can go from there.

Christian

hi there...
thanx...actually i'm a student from Malaysia...and i still new to learn about c++..so..if u have something important about c++..just tell me...now i'm learning about file text..but i still weak about bubble sort :rolleyes: ..give me something.. :)

Thank you for this tutorial. I was trying this way but did not know I had to add that file. Thank you very much.

system() insecure. use execl, execle, execv, or execve.

On a visual program how would this work? I have the opendialog all set, but when I press the button which should launch the program, it does nothing.

This is what I have:

Find->Filter = S"Text Files (*.txt)|*.txt|"
				 S"All files|";
			 Find->FilterIndex = 2;
			 Find->DefaultExt = S".txt|";
			 if (Find->ShowDialog() == DialogResult::OK)
			 { 
				 textBox5->Text = Find->FileName;
			 }
			 Find->OpenFile();

Any ideas?

On a visual program how would this work? I have the opendialog all set, but when I press the button which should launch the program, it does nothing.

This is what I have:

Find->Filter = S"Text Files (*.txt)|*.txt|"
				 S"All files|";
			 Find->FilterIndex = 2;
			 Find->DefaultExt = S".txt|";
			 if (Find->ShowDialog() == DialogResult::OK)
			 { 
				 textBox5->Text = Find->FileName;
			 }
			 Find->OpenFile();

Any ideas?

Hi,
Within the if condition
if (Find->ShowDialog() == DialogResult::OK)
{
textBox5->Text = Find->FileName;
///////----here--------------
}

use the various calls system() execl, execle, execv, or execve
just to start with use system("dir") later use better API as exec*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.