user3068649
user3068649

Reputation: 421

Redirect stdout to a external program in C/C++

I have a program called capture that reads the webcam data and output to the avconv program.

./capture | avconv -f mpegts udp://10.1.62.252:5050

Now I have to output to avconv inside my C program.

So, instead of output to the stoud:

fwrite(p, size, 1, stdout);

I need to do do something like that:

system("stdout | avconv -f mpegts udp://10.1.62.252:5050");

How can I do that?

Upvotes: 1

Views: 561

Answers (1)

Milan Patel
Milan Patel

Reputation: 422

You can use popen() for this purpose.

FILE *f = popen("avconv -f mpegts udp://10.1.62.252:5050","w");

then use fwrite() to write.

PS: Actually, this method is not redirecting stdout of your c program but it is using pipe stream concept to provide input to avconv from your code.

Upvotes: 4

Related Questions