probine
asked on
How to start a program from another program ?
I am using C++ in Linux.
Simple: I have a program that prints HELLO in the screen. Now, this program should call another program, let us say a program that in a new window will say THANK YOU FOR HELPING.
I know you can open files and write to files from a program, but I want now to start another simple program from the first program.
Thank you, and if you need more details, et me know it.
Simple: I have a program that prints HELLO in the screen. Now, this program should call another program, let us say a program that in a new window will say THANK YOU FOR HELPING.
I know you can open files and write to files from a program, but I want now to start another simple program from the first program.
Thank you, and if you need more details, et me know it.
If u have the executable of the second file
Then u could use
system ( execuatble path of second file ) ;
However, I doubt if this would give u the second file output in a new window
It would give the output in the same output widow as that of first
Amit
Then u could use
system ( execuatble path of second file ) ;
However, I doubt if this would give u the second file output in a new window
It would give the output in the same output widow as that of first
Amit
Sorry leflon,
I guess we started the same time
Amit
I guess we started the same time
Amit
ASKER
This is what I have:
1. A program called main.cpp
2. A program called test.cpp
This is what I have in main:
*************************
include<iostream>
using namespace std;
int main()
{
cout <<"Hello";
// I want to execute the program test.cpp here
}
This is what I have in test.cpp
************************** *
include<iostream>
using namespace std;
int main()
{
cout <<"THANK YOU FOR YOUR HELP";
}
Do I have to incude some header file or something ?
1. A program called main.cpp
2. A program called test.cpp
This is what I have in main:
*************************
include<iostream>
using namespace std;
int main()
{
cout <<"Hello";
// I want to execute the program test.cpp here
}
This is what I have in test.cpp
**************************
include<iostream>
using namespace std;
int main()
{
cout <<"THANK YOU FOR YOUR HELP";
}
Do I have to incude some header file or something ?
@Amit: yepp happens to me all the time :-)
oops somehow overread the first line >> I am using C++ in Linux
leflon
oops somehow overread the first line >> I am using C++ in Linux
leflon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great help and easy to understand... thank you leflon and SYS prog.
You both gave me a good answer... Can I split the points ?
You both gave me a good answer... Can I split the points ?
ASKER
Perhaps you can help me with this:
I need to print HELLO in the screen every 10 seconds.
What class do I include and how is the code ?
I need to print HELLO in the screen every 10 seconds.
What class do I include and how is the code ?
probine,
do you have to print a certain number of times or till a key is pressed?
you can use time_t (seconds since 1.1.1970) and the according time functions (include <time.h>).
time_t tNow;
time(&tNow); // getsystem time in seconds now
int ix = 0;
while(ix<10)
{
cout << "Hello";
while((tNow+10)>time(NULL) ) // loop till actual system time is 10 seconds greater than tNow
{
// use either
sleep(1); //stops thread for 1 second, check your man pages for header needed for this
// or
usleep(1000); //stops thread for 1000 microsecond, check your man pages for header needed for this
// you can omit the sleeps, but then the prog will use 100% of the system for the whole time it runs, which is not very good
}
time(&tNow);
}
leflon
do you have to print a certain number of times or till a key is pressed?
you can use time_t (seconds since 1.1.1970) and the according time functions (include <time.h>).
time_t tNow;
time(&tNow); // getsystem time in seconds now
int ix = 0;
while(ix<10)
{
cout << "Hello";
while((tNow+10)>time(NULL)
{
// use either
sleep(1); //stops thread for 1 second, check your man pages for header needed for this
// or
usleep(1000); //stops thread for 1000 microsecond, check your man pages for header needed for this
// you can omit the sleeps, but then the prog will use 100% of the system for the whole time it runs, which is not very good
}
time(&tNow);
}
leflon
depends a bit on the environment aou are in, but you can use
int system( const char *command );
to start another prog from your app.
if you can give us your env. we can give you other possibilities
hth
leflon