Re: File descriptors and screen and you

2007-02-08 Thread Andy Harrison

On 2/6/07, Alan Young [EMAIL PROTECTED] wrote:

I have a bit of perl code that I'm trying to make work:

sub DB::get_fork_TTY {

   open my $SCREEN, qq{31 screen -t 'Child $$' sh -c tty 13 ; sleep
100 |}
 or return '';

   my $tty = $SCREEN;

   return $tty;
}

I'm getting bad file descriptor errors, so I'm assuming screen is
cleaning up what it hands to it's children.  Which makes sense.

I want to avoid going the tmp file route if at all possible.  Is there a
way I can echo tty's output so that I can grab it from a filehandle?

I've tried a number of different methods.

Any pointers?




What exactly are you trying to accomplish with your script?

--
Andy Harrison


___
screen-users mailing list
screen-users@gnu.org
http://lists.gnu.org/mailman/listinfo/screen-users


Re: File descriptors and screen and you

2007-02-08 Thread Michael Schroeder
On 2/6/07, Alan Young [EMAIL PROTECTED] wrote:
 I have a bit of perl code that I'm trying to make work:

 sub DB::get_fork_TTY {

open my $SCREEN, qq{31 screen -t 'Child $$' sh -c tty 13 ; sleep
 100 |}
  or return '';

my $tty = $SCREEN;

return $tty;
 }

 I'm getting bad file descriptor errors, so I'm assuming screen is
 cleaning up what it hands to it's children.  Which makes sense.

The problem is actually something else (but you're right, screen
cleans up the filedescriptors): the 'screen' command in your
script just tells the screen backend process that it should create
a new window, so the new window is no child of your script and
cannot share the file descriptor.

 I want to avoid going the tmp file route if at all possible.  Is there a
 way I can echo tty's output so that I can grab it from a filehandle?

You need some interprocess communication way. Some ways could be
- a tmp file (but you don't like that)
- a named pipe (but that's close to a tmp file)
- some code using sockets (complicated)
- using /proc/pid/fd to access the file descriptors of your
  process. But that's not very portable. Something like:

open my $SCREEN, qq{screen -t 'Child $$' sh -c tty /proc/\$\$/fd/1 ; 
sleep 100 ; sleep 10 |}

  (The sleep 10 is needed to keep the process alive long enough.)

Cheers,
  Michael.

-- 
Michael Schroeder   [EMAIL PROTECTED]
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}


___
screen-users mailing list
screen-users@gnu.org
http://lists.gnu.org/mailman/listinfo/screen-users


Re: File descriptors and screen and you

2007-02-08 Thread Alan Young

Michael Schroeder wrote:

I want to avoid going the tmp file route if at all possible.  Is there a
way I can echo tty's output so that I can grab it from a filehandle?


You need some interprocess communication way. Some ways could be
- a named pipe (but that's close to a tmp file)


I'm not as familiar with the shell as a I should be.  How would I go 
about using a named pipe?  And what's the differences between that and a 
tmp file?


It's been suggested that if I want to make this really portable then a 
tmp file is actually the best way to go, so it's not off the list, just 
low on it.



- some code using sockets (complicated)


and more trouble than its worth.

Thanks for the input and help.

Alan


___
screen-users mailing list
screen-users@gnu.org
http://lists.gnu.org/mailman/listinfo/screen-users


File descriptors and screen and you

2007-02-06 Thread Alan Young

I have a bit of perl code that I'm trying to make work:

sub DB::get_fork_TTY {

  open my $SCREEN, qq{31 screen -t 'Child $$' sh -c tty 13 ; sleep 
100 |}

or return '';

  my $tty = $SCREEN;

  return $tty;
}

I'm getting bad file descriptor errors, so I'm assuming screen is 
cleaning up what it hands to it's children.  Which makes sense.


I want to avoid going the tmp file route if at all possible.  Is there a 
way I can echo tty's output so that I can grab it from a filehandle?


I've tried a number of different methods.

Any pointers?


___
screen-users mailing list
screen-users@gnu.org
http://lists.gnu.org/mailman/listinfo/screen-users