Reputation: 1132
I am trying to write a program in c++
for QNX
which executes other programs.
For this I have 4 files to be handled.
file1
file2.l
file3.c
file4.bin
The algorithm is
if file1 is not present then execute file2.l
Execute file3.c
Execute file4.bin
This is the code which I have tried.
#include<fstream>
#include<iostrea>
using namespace std;
int main(){
ifstream ifile;
ifile.open("file1");
if(!ifile){
// system("Code to run file2.l program in termnal")
}
// system("Code to run file3.c program in termnal")
system("./file4.bin")
I need to know how to execute file2.l
and file3.c
using c++
in QNX
Upvotes: 0
Views: 554
Reputation: 7726
#include <iostream>
using namespace std;
inline bool fileCheck(const string &name)
{
if (FILE *file = fopen(name.c_str(), "r"))
{
fclose(file);
return true;
}
else
{
return false;
}
}
int main(void)
{
// Replace with your own code
if (fileCheck("time.exe"))
{
// exists...
system("swap.exe");
}
else
{
// doesn't exists...
system("swap.exe");
}
return 0;
}
The program firstly creates an inline function to check the existence of a file in a fast way and then the main() occurs which does your required works.
Upvotes: 0
Reputation: 11
System() is only for executing system functions, such as 'cp' or 'shutdown'. To launch a program, you can use spawn() or spawnv() functions.
Upvotes: 1