LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-24-2004, 02:21 AM   #1
arvind_tyche
LQ Newbie
 
Registered: May 2004
Posts: 7

Rep: Reputation: 0
Default FDs


Hello,

I would like to know how do I change the default file descriptor for a process for a FD which I define..? I think of redirecting all the Outputs of the process to a file.


Thanks .....

Bye...
 
Old 06-24-2004, 06:53 AM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
"default file descriptor"? You mean stdout and stderr? To replace those for a process, you can 'close' the old ones and 'dup'(licate) others into their place.
 
Old 06-24-2004, 10:02 AM   #3
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
If you want to redirect stdin, stdout, and stderr, the function you want is probably dup2(). e.g.

Code:
int fd;
fd = open("/dev/null", O_WRONLY);
if (fd < 0)
    err(EXIT_FAILURE, "crap");
if (dup2(fd, fileno(stdout)) < 0)
    err(EXIT_FAILURE, "dup2");
/* now stdout goes to /dev/null */
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Details about default web Browser & default Email client sudhasmyle Linux - Software 4 06-15-2006 11:45 AM
DMA works but not by default (despite "use DMA by default" kernel) mehlkelm Linux - Hardware 7 04-11-2005 03:29 PM
Default Drowser & Default E-mail Cli sudhasmyle Linux - Networking 1 11-20-2004 10:42 AM
setting default page size and default tray lived4eva Linux - General 1 11-04-2003 02:39 PM
New Virtual Servers Default to Default Server Page? DigiDave Linux - Software 4 10-18-2003 03:23 AM


All times are GMT -5. The time now is 04:41 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration