C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-22-2005, 06:06 AM   #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
ylvawandel is offline   Reply With Quote
Old 10-22-2005, 06:21 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,710
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.

Salem is offline   Reply With Quote
Old 10-24-2005, 01:32 PM   #3
.
 
Join Date: Nov 2003
Posts: 293
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.
jim mcnamara is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ARGH: getline wants 3 args when I give 2, and 2 args when I give 3? BrianK Windows Programming 1 06-29-2004 05:23 PM
Command line args lpmrhahn C Programming 5 04-12-2004 09:54 PM
resources with dev-c++ lambs4 Windows Programming 0 04-13-2003 06:06 AM
Multiple Command Line Args mart_man00 C Programming 10 08-16-2002 02:15 PM
Contest Results - May 27, 2002 ygfperson A Brief History of Cprogramming.com 18 06-18-2002 01:27 PM


All times are GMT -6. The time now is 04:06 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22