Thread: execvp("tail -1f /var/log/apache/", args) ;

  1. #1
    Registered User
    Join Date
    Oct 2005

    execvp("tail -1f /var/log/apache/", args) ;


    This code only gives the "ls" output.
    Although running the command "tail -1f /var/log/apache/"
    directly in UNIX it is working, ie it's printing out
    the logglines from that webserver...

    Please Help!!

    #include <stdio.h>
    #include <stropts.h>
    #include <poll.h>
    #include <unistd.h>
    int main(void)
    	char *args[] = {"tail -1f /var/log/apache/", NULL};
    	execvp("tail -1f /var/log/apache/", args) ;
    	execvp("ls", args) ;


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    So why not just write a shell script?

    The only reason it does "ls" is because your tail execl call fails miserably with an error. If it succeeded, you would not see the "ls" at all. execl level functions are one-way trips, if they succeed in running a new program they do not return.

    Moved to linux forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Join Date
    Nov 2003
    If you have to use "tail" try popen():
    #include <stdio.h>
    int main(void)
        FILE *fp=popen("tail -1f /var/log/apache/", "r");
        char tmp[256]={0x0};
        while(fgets(tmp, sizeof(tmp), fp)!=NULL
            fprintf(stdout,"%s",  tmp);
        return 0;
    It would be faster to use fseek to get to the end of the log file, back pedal to the start of the last record, read it, print it. All in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2004, 05:23 PM
  2. Command line args
    By lpmrhahn in forum C Programming
    Replies: 5
    Last Post: 04-12-2004, 09:54 PM
  3. resources with dev-c++
    By lambs4 in forum Windows Programming
    Replies: 0
    Last Post: 04-13-2003, 06:06 AM
  4. Multiple Command Line Args
    By mart_man00 in forum C Programming
    Replies: 10
    Last Post: 08-16-2002, 02:15 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM