stop output from apperaring from stdout and stderr

  • Thread starter pranav.choudhary
  • Start date
P

pranav.choudhary

Hi,
In my C program, i fork a new process and use exec to execute a new
program in the child process. But i don't want the child process to
write anything to the stdout or stderr. How can i do that?

--pranav
 
F

Flash Gordon

Hi,
In my C program, i fork a new process and use exec to execute a new
program in the child process. But i don't want the child process to
write anything to the stdout or stderr. How can i do that?

In standard C you can't, you also can't fork or exec. Try a group
dedicated to your system such as comp.unix.programmer
 
S

selvesteen

Flash said:
In standard C you can't, you also can't fork or exec. Try a group
dedicated to your system such as comp.unix.programmer

Please note that The exec*() system calls, in all their forms, loads a
program from an ordinary, executable file into the current process,
replacing the current program. So the your child process have no
control on 'exec'- ed program. Instead you may redirect all the stdout
or stderr in exec-ed program.
 
J

Joe Estock

Can i redirect stdout and stderr to somthing NULL. If yes, how?

Like you have already been told, try a newsgroup dedicated to your
operating system (comp.unix.programmer). We only deal with standard c
here and standard c knows nothing about stdout or stderr redirection.

<Semi-OT>
Now, if you want to close stdout and stderr that can be done as well.
Remember, stdout and stderr are both pointers to tyoe FILE * and can be
manipulated with fclose and friends.
</Semi-OT>

<OT>
Call fclose() on stdout and stderr from within the child pid when you
fork().
</OT>

If you need anymore help that doesn't pertain to standard c, please
visit the above mentioned newsgroup.


Joe
 
K

Kenneth Brody

Joe said:
Can i redirect stdout and stderr to somthing NULL. If yes, how?

Like you have already been told, try a newsgroup dedicated to your
operating system (comp.unix.programmer). We only deal with standard c
here and standard c knows nothing about stdout or stderr redirection. [...]
<OT>
Call fclose() on stdout and stderr from within the child pid when you
fork().
</OT>
[...]

Causing "bad things"[tm] to happen. Any printf()/sprintf(stderr) will
now cause undefined behavior. And, perhaps worse, the next fopen() may
return the same FILE* as was previously occupied by stdout/stderr, and
writing to stdout/stderr will now go to the fopen()ed file.

On the other hand, your platform may have the ability to freopen stdout
and stderr to a bit-bucket, such as Unix's "/dev/null".

Check a group related to your O/S for more details.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top