Thread: execvp("tail -1f /var/log/apache/www.cs.umu.se/access_log", args) ;

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    execvp("tail -1f /var/log/apache/www.cs.umu.se/access_log", args) ;

    Hello,

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

    Please Help!!

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

    KrY

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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
    Posts
    307
    If you have to use "tail" try popen():
    Code:
    #include <stdio.h>
    int main(void)
    {
        FILE *fp=popen("tail -1f /var/log/apache/www.cs.umu.se/access_log", "r");
        char tmp[256]={0x0};
      
        while(fgets(tmp, sizeof(tmp), fp)!=NULL
        {
            fprintf(stdout,"%s",  tmp);
        }
        pclose(fp);
        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 Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM