Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-15-2008, 08:03 AM
BlueDream BlueDream is offline
Newbie
 
Join Date: May 2008
Posts: 4
Rep Power: 0
BlueDream is on a distinguished road
Default stdout redirecting

I'm using some system calls in my code for example:

system ( "pr who.list" );

and instead of just printing it straight out to screen I want to redirect it to a file descriptor that I've set up that is a named pipe.... for example...

1. int newfd;
2. int old_state = dup ( (int)stdout );
3. dup2 ( newfd, stdout );
4. close (stdout );
5. mknod ( "myfifo", S_IFIFO | 0666, 0 );
6. newfd = open ( "myfifo", O_WRONLY );
7.
8. system ( "pr who.list" );
9.
10. dup2 ( old_state, stdout );

I thought line 2 would of done my redirection for me so that when 'pr' tries to write to stdout it will actually write to my file descriptor which another process will read and do something with, but I'm not getting anything from the pipe.

It just returns to my command line until I exit the program and then it squirts it out to the screen...

Last edited by BlueDream; 05-15-2008 at 11:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 03:07 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads