Найти файл по пути и выполнить его с помощью терминала В Linux с языком C - PullRequest
0 голосов
/ 11 апреля 2019

Я пытаюсь написать программу, которая будет печатать в цикле while, для ввода местоположения, если местоположение существует на пути, выполнить его, если не записать, файл не найден, Более того, если пользователь вводит, он покидает программу.

Я попытался использовать функцию штрихов, поскольку вижу, что ":" разделяет папки.как только я нашел путь, я должен использовать fork и hten execv и дождаться окончания процесса.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void main() {
    char *p;
    int i = 0;
    const char s[2] = ":";
    char command[400];
    char *tok_arr[200];
    char *temp;

    printf("\nlets start\n");
    p = getenv("PATH");

    /* 
       Here should be the strtok..which does not work for me... 
    */

    /* 
       After that should I do one more while in order to get all the folders of getenv seperated with " : ". ? 
    */

    do {
    /* 
       Here I should print what app/file the user would like to use
       if I can found it than excute it,otherwise print a message that
       file not found.
       untill the user prints leave.
    */
    while(strcmp(command,leave) == 1);  
}
...