![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Oct 2005
Posts: 4
| execvp("tail -1f /var/log/apache/www.cs.umu.se/access_log", args) ; 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 | |
| | #2 |
| and the hat of Jobseeking 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 |
| Salem is offline | |
| | #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;
}
|
| jim mcnamara is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |