创建c ++程序以在qnx中执行其他程序

问题描述 投票:0回答:2

我正在尝试在c++中为执行其他程序的QNX编写程序。

为此,我有4个文件要处理。

file1
file2.l
file3.c
file4.bin

算法是

if file1 is not present then execute file2.l
Execute file3.c
Execute file4.bin

这是我尝试过的代码。

#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")

我需要知道如何使用file2.l中的file3.c执行c++QNX

c++ qnx
2个回答
1
投票

System()仅用于执行系统功能,例如'cp'或'shutdown'。要启动程序,可以使用spawn()或spawnv()函数。


0
投票
#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;
}

程序首先创建一个内联函数来快速检查文件的存在,然后出现main()来完成所需的工作。

© www.soinside.com 2019 - 2024. All rights reserved.