Public feed
#887361
#include <stdio.h>
#include <string.h>
void produce_arglist(char *str, char **ret) {
char *c = strtok(str, " ");
ret[0] = c;
int i = 1;
while ((c = strtok(NULL, " ")) != NULL) {
ret[i] = c;
i++;
}
ret[i] = NULL;
}
int exec_piped(char **pipelist[], int num) {
//
}
int main() {
char input[] = "ps -A | grep -i sagar | sed -e | wc -l";
int i;
char *argstr[16];
i = 1;
argstr[0] = strtok(input, "|");
while ((argstr[i] = strtok(NULL, "|")) != NULL)
i++;
char **pipelist[i];
int j;
for (j = 0; j<i; j++) {
// i varies from 0 to num_of_piped_commands"
char *ret[i];
produce_arglist(argstr[j], ret);
pipelist[j] = ret;
printf("running produce_arglist(%s, ret)...\n", argstr[j]);
printf("filling pipelist[%d] with ret...\n", j);
printf("pipelist[%d] now contains:\n", j);
int q;
for (q = 0; ret[q] != NULL ; q++)
printf("\t'%s'\n", ret[q]);
}
// exec_piped(pipelist, j);
return 0;
}