Thread: Storing the result of execvp to a char array in C

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    Storing the result of execvp to a char array in C

    I would like to know how to store the result of execvp to a char array as a string.

    Below is my code:

    Code:
    int main () {
        char response[1000];
        char *buffer[100];
         int pid, status;
         printf("Please enter the shell command:  ");
         scanf("%s",&response);
         pid = fork();
         if (pid < 0) {
                        printf("Unable to create child process, exiting.\n");
                        exit(0);
                        }
         if (pid == 0) {
                    printf("I'm the child.\n");
                    *buffer = response;
                    execvp(*buffer,buffer);
                    printf("execvp failed\n");
                         } 
                         
         else{
              wait(&status);
              exit(0); 
              }
    }
    If a user types "ls" execvp displays the result of "ls" to the screen. I would like to store this in a char array as a string. Can anyone help me?
    THanks in advance.

    James
    Last edited by kponenation; 12-14-2005 at 11:27 PM.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    2
    Problem solved!!!
    You don' t need to reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM