Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
stdout v stderr (Tcl, Perl, Shell)
When you're programming, you shouldn't write code to read directly from the keyboard and write to the screen .... what if you want to have your program read from or write to a file sometimes? Instead, you should write code to read from stdin (Tcl) or STDIN (Perl) and write to stdout (Tcl) or STDOUT (Perl). Then you can re-direct from and to file!

But wait .... if you redirect ALL your output to a file, including error messages, you'll find it pretty irritating having to look in a file to see if the program worked. Better to use the alternative stderr (Tcl) or STDERR (Perl) output channel for warnings, errors, and status reports.

Here's a Tcl example of code written that way:

puts -nonewline stderr "Who are you? "
flush stderr
set yername [gets stdin]
 
puts "Hello $yername and welcome"
puts stderr "Job Completed"


And here's an example of that program running:


arth-wind-and-fire:~/dec07 grahamellis$ tclsh tt
Who are you? Graham
Hello Graham and welcome
Job Completed
earth-wind-and-fire:~/dec07 grahamellis$ tclsh tt > xx.txt
Who are you? Graham
Job Completed
earth-wind-and-fire:~/dec07 grahamellis$ cat xx.txt
Hello Graham and welcome
earth-wind-and-fire:~/dec07 grahamellis$

(written 2007-12-10 14:56:14)

 
Associated topics are indexed under
T209 - Tcl/Tk - File and Directory Handling
P106 - Perl - File Handling

Back to
Effective Java training - the bootcamp approach
Previous and next
or
Horse's mouth home
Forward to
Lexical v Arithemetic testing, Bash and Perl

Some other Articles
Cliff Lift simulator- Lynton to Lynmouth - in Tcl/Tk
fill and expand on Tcl/Tk pack command
Curley brackets v double quotes - Tcl, Tk, Expect
Lexical v Arithemetic testing, Bash and Perl
stdout v stderr (Tcl, Perl, Shell)
Effective Java training - the bootcamp approach
Perl, PHP, Python, Tcl, Linux, MySQL, Ruby courses ...
Python Script - easy examples of lots of basics
All the special characters in HTML ...
10 training days to Christmas.
1696 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho