g ++中的system()函数

时间:2018-09-03 19:08:38

标签: c++

在这里从日志中删除“ cpp”

#include <iostream>
#include <stdlib.h> // system
#include "header.h"
#include "ConfigFile.h"

using namespace std;

int glogs(int answer)
{
    ConfigFile cf("config.txt");
    string lang;
    double dChannel, dCore;
    lang = (const string)cf.Value("Main_Setting", "LANG");
    dChannel = cf.Value("Main_Setting", "CHANNEL");
    dCore = cf.Value("Main_Setting", "CORES");
    system("clear");
    if(lang == "ENG") {
        cout << "Remove the all Server logs...\n";
        for(int i=1; i < dChannel+1; i++){
            for (int c=1; c < dCore+1; c++){
                system("cd /usr/home/game2/channel" + i + atoi("/core") + c + atoi("/ && rm -R syslog && rm -R syserr"));
            }
        }
        cout << "delete logs done return to main menu...\n";
        system("sleep 10");
        system("./start");
        return answer;
    }
    if(lang == "DE"){
        cout << "Loesche alle Server logs...\n";
        for(int i=1; i < dChannel+1; i++){
            for (int c=1; c < dCore+1; c++){
                system("cd /usr/home/game2/channel" + i + atoi("/core") + c + atoi("/ && rm -R syslog && rm -R syserr"));
            }
        }
        cout << "loeschen erfolgreich, rurueck zum Hauptmenue...\n";
        system("sleep 10");
        system("./start");
        return answer;
    }
}

该行没有发出警告或错误,但他没有工作

system("cd /usr/home/game2/channel" + i + atoi("/core") + c + atoi("/ && rm -R syslog && rm -R syserr"));

我已经在堆栈中搜索了任何住所,但是我没有找到解决我问题的方法。

1 个答案:

答案 0 :(得分:0)

您的行

AbstractControlOptions

应该是这样

system("cd /usr/home/game2/channel" + i + atoi("/core") + c + atoi("/ && rm -R syslog && rm -R syserr"));
需要

c ++ 11进行编译,而我没有测试代码。我建议不要使用const auto path = "/usr/home/game2/channel" + std::to_string(i) + "/core" + std::to_string(c); const auto cmd1 = "rm -R " + path + "/syslog"; const auto cmd2 = "rm -R " + path + "/syserr"; system(cmd1.c_str()); system(cmd2.c_str()); ,而应该使用systemunlink或提供递归删除文件夹的类和功能的c ++库。