Re: Question about closeing and opening stdin
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 [EMAIL PROTECTED] [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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Question about closeing and opening stdin
How do I close then open stdin and keep it set to the same terminal as when it was closed? Everything I've tried so far has met with failure accept this works sort of and I don't get why: signal( SIGALRM, MGPMrTimer ); alarm( 300 ); /* time out in 5 minutes */ answer = getc(stdin); the signal handler just closes descriptor 0 if a timeout occrs: close( 0 ) then to reset stdin I tried this: stdinFileDescriptor = open( /dev/tty, O_RDWR ) ) stdin = fdopen( stdinFileDescriptor, r ); and it works in this instance of the program, but if a second instance is started the second instance can't close stdin. I got the above idea from google, what I don't understand though is there is no /dev/tty! So anyone have any suggested books I might read or tips so I can learn how to do this right, and understand why it works? Thank you, Mike ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Question about closeing and opening stdin
On Tuesday 22 November 2005 10:50, Michael C. Shultz wrote: How do I close then open stdin and keep it set to the same terminal as when it was closed? Everything I've tried so far has met with failure accept this works sort of and I don't get why: signal( SIGALRM, MGPMrTimer ); alarm( 300 ); /* time out in 5 minutes */ answer= getc(stdin); the signal handler just closes descriptor 0 if a timeout occrs: close( 0 ) then to reset stdin I tried this: stdinFileDescriptor = open( /dev/tty, O_RDWR ) ) stdin = fdopen( stdinFileDescriptor, r ); and it works in this instance of the program, but if a second instance is started the second instance can't close stdin. I got the above idea from google, what I don't understand though is there is no /dev/tty! So anyone have any suggested books I might read or tips so I can learn how to do this right, and understand why it works? Thank you, Mike Please disregard the previous post, I figured it out, simple solution. -Mike ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]