Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirection stdout with low level api in C

Is there a way to redirect stdout with low level API... haven't found a function or a way to actually do this....

like image 690
Necronet Avatar asked Feb 12 '26 19:02

Necronet


2 Answers

The dup system call should let you redirect stdout, as shown in this example.

freopen also will work, if you're redirecting to a file, but dup can also be used with pipes and sockets.

like image 178
Jim Lewis Avatar answered Feb 15 '26 17:02

Jim Lewis


I believe dup2(fd,1) does the trick, e.g. after opening fd using open().

like image 32
mvds Avatar answered Feb 15 '26 18:02

mvds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!