The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
changing /cn@0:console file permissions ErnieG Security 4 12-04-2007 08:39 AM
permanent redirection of standard input gfhgfnhhn Shell Programming and Scripting 6 11-01-2006 04:52 AM
input redirection question luistid Shell Programming and Scripting 0 08-22-2006 07:28 AM
redirection stdin whited05 Shell Programming and Scripting 2 10-12-2005 02:03 PM
Input Redirection majeed73 UNIX for Dummies Questions & Answers 6 07-08-2002 03:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2001
nauman nauman is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 3
Arrow Changing stdin from file redirection to console input

Hi

I am doing file redirection at console for use by my binary.

%console%> bin &lt inputfile

After reading in the entire file, I want my program to continue taking input from the console. So essentially I want to redirect stdin back to console. But I cant figure out how to do it.

I am using GNU compiler on Linux and Solaris. Can anyone help me in this regard.

Thanx
Nauman

Last edited by nauman; 09-28-2001 at 07:01 PM..
  #2 (permalink)  
Old 09-28-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
I'm not exactly clear what
you are trying to do but
after your done reading the file,
try closing all fd's

// assuming you have no more that 10 files open
for(i = 0; i < 10; i++)
{
if(close(i) < 0)
break;
}

...then open a new file. The fd will be 0 (stdin).
  #3 (permalink)  
Old 09-29-2001
nauman nauman is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 3
Question

I am not opening any file in my program. The file is being redirected to stdin by the OS.

bin &lt inputfile

I am using gets() to read, which not to mention read from the stdin. After I am finished reading the file, I want gets() to continue reading from console input.

Are u implying that file redirection causes a fd attached to stdin. If so when I reopen the fd, what argument should I give it, to attach it to console input.

I am going to try it next anyway and see what happens.

Thanx

Nauman
  #4 (permalink)  
Old 09-29-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
When a program is loaded by the OS,
it is automatically given 3 open files...

stdin -> fd=0
stdout -> fd=1
stderr -> fd=2

By closing all fd's you guarantee that
the next file you open...

open(...)

...will be assigned fd 0
  #5 (permalink)  
Old 09-29-2001
nauman nauman is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 3
Thumbs up

Thanx. Ur comments really helped. Besides I also got to know how OS works and how to redirect stdin.

Thanx and regards
Nauman
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 -4. The time now is 09:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0