CrazyEngineers
  • UNIX COMMANDS

    vinuta

    vinuta

    @vinuta-sKKXBQ
    Updated: Oct 26, 2024
    Views: 1.2K
    #include <stdio.h>
    main()
    {
    char str[10];
    int pid;
    pid=fork();
    if(!pid)
    {
    printf("child process");
    printf("enter the command");
    scanf("%s",&str);
    system(str)
    printf("finished with child ");
    }
    else
    wait();
    retrun(0);
    } 
    output:-
    child process:-
    enter the command
    ls -l


    with this output i m just getting file names ...but i need ls -l --- lists files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Jayaram Reddy

    MemberDec 5, 2014

    Here in the command it will take only "ls" why because you are reading the string using scanf. It will read only one string here ls -l are two strings. So use "gets" function to read the string.....
    But here one warning will be there that u are reading a string using its address so it is better to use pointer declaration, not an array. But it is ignorable....😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register