【问题标题】:Creating a c++ Program to execute other programs in qnx在qnx中创建一个c++程序来执行其他程序
【发布时间】:2020-04-20 06:50:48
【问题描述】:

我正在尝试在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")

我需要知道如何在QNX 中使用c++ 执行file2.lfile3.c

【问题讨论】:

    标签: c++ qnx


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      #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() 来完成您所需的工作。

      【讨论】:

        猜你喜欢
        • 2011-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-15
        • 2018-01-28
        • 1970-01-01
        相关资源
        最近更新 更多