• [^] # Re: execle(...);

    Posté par . En réponse au message Lancer un programme, comment ?. Évalué à 1.

    J'ai amélioré :
    voici les changements (tout ce qui précède tableau = (char **)malloc(.....
    int my_system (std::string commande) {
    std::vector<std::string> liste;
    std::string cmd, element;
    char **tableau;
    bool in_quotes = false;
    int pid, last_find = 0,i, retour = -1;
    cmd = commande + " ";
    for (i=0 ; i < cmd.size() ; i++) {
    if (cmd[i] == '"') {
    in_quotes = !in_quotes;
    }
    if ((cmd[i] == ' ') and (!in_quotes)) {
    element = cmd.substr(last_find, i-last_find);
    if (element[0]=='"') {
    element = element.substr(1);
    }
    if (element[element.size()-1]=='"') {
    element = element.substr(0, element.size()-1);
    }
    liste.push_back(element);
    last_find = i+1;
    }
    }