Skip to content
Advertisement

Tag: dup2

Can’t redirect printf to pipe

I want to redirect the output of printf to a pipe, but for some reason it doesn’t seem to work. What does work is using write instead. This is my program if I replace write with the commented line, my program just blocks Answer Either add a new line character (n) to your output or use fflush() as Barmar suggests:

What end of stream dup2 change?

What end of the stream does dub2 ( ) change is it the end the OS is connected to or the end connected to application . this code redirect output to file and not the screen which means that input side of stream is connected now to the file right . Answer Before the dup2(), the file descriptor table for

dup2 paramater order confusion

I have written this simple program: What i want is, redirect the output of ls – l to a file called “theFile.txt”. The code works as i expect. What confuses me here is the order of dup2 parameters. I believe that correct order should be dup2(1, fd) – considering fd as the newFD and 1 as the oldFD. But the

Advertisement