I was trying to read from the STDIN file descriptor in /dev/fd/0
This is what I wrote, I just want to print every command I ever type on the command shell. I wrote this in Perl but its not good enough:
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, "<", "/dev/fd/0" or die "bububububu";
while (<$fh>) {
print $_."\n";
}
close $fh;
So it doesn't print anything although it gets stuck. Does anyone know how to do it??? If this is not possible can I put all the commands in a file and then read them from the '0' file handle somehow. I just want to capture every command which goes through to the system.
Example file:
#!/usr/bin/perl
use strict;
use warnings;
system("./.file2");
and then file2 is:
echo this is hard!!!
So I want my program to run the first file. When I read the '0' filehandle, I wish to store all the lines run in an array somehow.
MAJOR EDIT: I THINK YOU MISUNDERSTOOD ME. I KNOW ABOUT STDIN AND HOW IT WORKS. THE THING IS I DON'T WANT THE SCRIPT TO READ FOR INPUTS FROM THE STDIN. I WANT THE SCRIPT TO READ FROM WHAT I TYPE IN THE SHELL PROMPT. SO LETS SAY I RUN THE FILE AND THEN I OPEN ANOTHER TEMINAL AND THEN I TYPE THE COMMANDS IN THE TERMINAL. I WANT THE SCRIPT TO RECOGNIZE THOSE LINES AND SAVE THEM IN AN ARRAY.