Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Nov 2005 15:19:16 -0800
From:      "Michael C. Shultz" <ringworm01@gmail.com>
To:        Joan Picanyol i Puig <pica@biaix.org>, freebsd-hackers@freebsd.org
Subject:   Re: Question about closeing and opening stdin
Message-ID:  <200511231519.17177.ringworm01@gmail.com>
In-Reply-To: <20051123192137.GA3559@grummit.biaix.org>
References:  <200511221050.49807.ringworm01@gmail.com> <20051123192137.GA3559@grummit.biaix.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 23 November 2005 11:21, Joan Picanyol i Puig wrote:
> [private reply, I'm 100% unsure I understand what you want]
>
> * Michael C. Shultz <ringworm01@gmail.com> [20051122 19:58]:
> > How do I close then open stdin and keep it set to the same terminal
> > as when it was closed?
>
> ? If it's closed, you've lost your file descriptor.
>
> > and it works in this instance of the program, but
> > if a second instance is started the second instance can't
> > close stdin.
>
> I seems like you want "file descriptor passing". You can pass
> fd's over pipes.
>
> qvb
> --
> pica

Here is the solution that finally worked in my case:

local_stdin = fopen( "/dev/stdin", "r" );
answer	= getc( local_stdin );

if timeout:
fclose( local_stdin );


After answer is handled I then just:

fclose( local_stdin );

and leave it closed untill needed again

I am able to open and close this local_stdin
without adversly affecting the global stdin, don't
know if it's "the right thing to do" but it works
with every  test I've thrown at it so far.

-Mike




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511231519.17177.ringworm01>