Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2 STDIN and Redirection

Up until this point we have assumed that is always going to be input that comes directly from the user.s keyboard. Users familiar with the concept of I/O redirection available in Linux and UNIX shells will be aware that it is also possible to redirect the output from either another program or use the contents of a file so that it appears to be keyboard input.

Input from a file can achieved using "<" I/O redirection on the command line when we invoke our Perl script. For example, assuming we had called the above example .showtext. and given it appropriate execute permissions it could be invoked as follows:

./showtext < /etc/passwd
Assuming you are on a Linux or UNIX based system this should result in the contents of the /etc/passwd file being displayed in the terminal window as if the user had typed it in on the keyboard.

Output from other programs can similarly be redirected as input to a Perl script using the pipe (|) command. For example to divert the output from the .ls. command:

ls -l | ./showtext
This will display the output from the ls -l command as though it too was typed by the user at the keyboard.

 
 
  Published under the terms of the GNU General Public License Design by Interspire