man -s2 exec. Explain why it is
that exec only ever returns -1.
execvp in APUE and/or
the exec man page.
Consider the following program, stdinwc:
1 #include <stdio.h> 2 #include <string.h> 3 #include <unistd.h> 4 5 int main() 6 { 7 char buff[128]; 8 char *newargv[32]; 9 int i = 0; 10 11 newargv[i++] = "wc"; 12 13 while(fscanf(stdin,"%s",buff) > 0) 14 newargv[i++] = strdup(buff); 15 16 newargv[i++] = NULL; 17 18 execvp("wc",newargv); 19 20 return 0; 21 }
stdinwc and the
regular old wc? NOTE: you should be able to sum
it up in one line! The following example of the program
in action should help you think about it:
bash$ ls -1 | perl -e 'while(<>){if($_=~/(.*).c.html/){print "$1.c\n";}}' | stdinwc
12 35 223 bar.c
14 39 300 foo.c
37 124 897 plotter.c
24 94 573 spacekill.c
21 33 284 stdinwc.c
13 38 253 supersimplespacekill.c
44 150 1111 wrapper.c
165 513 3641 total
what the perl call in the pipeline does isn't
relevant, though I can tell you that for any file
name.c.html
it prints out
name.c.