Thursday 15 September 2011

Piping in windows CMD doesn't work for two programs written in C -



Piping in windows CMD doesn't work for two programs written in C -

the codes 2 programs are,

p1.c:

#include <stdio.h> int main () { printf("program1"); homecoming 0; }

p2.c:

#include <stdio.h> int main (char argc, char *argv[]) { printf("%s", argv[1]); printf(" | program2"); homecoming 0; }

when p1 | p2 entered in cmd, expected output is: program1 | program2. output is: (null) | programme 2. output of p1 not taken in p2. how can resolve issue?

you don't understand how piping works. pipe something else means "use standard output of programme 1 , provide standard input of programme 2." using argv, assuming output of programme 1 going arguments of programme 2 , isn't correct. need scanf (or equivalent) stdin in order result looking for.

either or need invoke p1 in such way output fed in argument.

c cmd command-prompt piping

No comments:

Post a Comment