- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Echo to StdErr
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 01:57 PM
тАО08-21-2001 01:57 PM
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 02:03 PM
тАО08-21-2001 02:03 PM
Re: Echo to StdErr
How about
echo "your_message" 1>&2
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 02:18 PM
тАО08-21-2001 02:18 PM
Re: Echo to StdErr
By default both STDOUT and STDERR are displayed on your terminal.
Within a script if you want to send the display of STDOUT to STDERR you could do something like
echo "message" 2>err_log 1>&2
where your STDERR is being sent to err_log and you are forcing STDOUT to be redirected to STDERR (which is basically err_log)
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 02:36 PM
тАО08-21-2001 02:36 PM
Re: Echo to StdErr
Just curious - what's the difference in the outputs of the conventional of redirection like
echo "my process" > errlog 2>&1
and the one you stated?
I am very much interested to know the case where Seth wanted to use stdErr.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 02:59 PM
тАО08-21-2001 02:59 PM
Re: Echo to StdErr
Actually AFAIK if you redirect STDOUT and STDERR to the same file, then it doesn't matter if you are using 2>&1 or 1>&2
Also I don't believe there is any difference in
echo "messages" > error.log 2>&1 and
ehco "messages" 2>error.log 1>&2
Since both the STDOUT and STDERR are getting redirected to the same file(error.log).
The only reason i specified 2>error_log is because sometimes i want STDOUT and STDERR to go to different files.
-Regards
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 03:12 PM
тАО08-21-2001 03:12 PM
Re: Echo to StdErr
echo my_message 1>&2 seems to work fine for what I wanted, but it would be better if I could prevent it from going to STDOUT as to keep it from wrighting to the log file as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 03:37 PM
тАО08-21-2001 03:37 PM
Re: Echo to StdErr
So, it is just the same if you do
echo "message" 2>&1 or simply
echo "message".
After understanding your task, I feel you can do this way.
some_commands > /tmp/yourlogfile
You are deliberately not specifying the StdErr redirection here so it will by default output to the terminal. However, the StdOut will go to yourlogfile.
What do you say?
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 04:19 PM
тАО08-21-2001 04:19 PM
Re: Echo to StdErr
If you do
echo "messages" 1>&2
both STDOUT and STDERR will be displayed on your screen
echo "messages" 2>error_log
will display STDOUT to screen and STDERR to the error_log file
echo "messages" >error_log
will display STDERR to the screen and STDOUT to the error_log file
echo "messages" >error_log 2>&1
will redirect both STDOUT and STDERR to the file error_log
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 04:33 PM
тАО08-21-2001 04:33 PM
Re: Echo to StdErr
I've got a program that populates files with certain information. Within that program it calles another script
Other_script > log_file
Within the other script I have
echo my_message 1>&2
That way I see my_message as if it were eched to the terminal from the original scrip, even though it's comeing from the Other_scrip and getting into the log file as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2001 07:17 PM
тАО08-21-2001 07:17 PM
Re: Echo to StdErr
From the above, I perceived this is what u mean:
1.The script Other_script will produce stderr.
2.You need to redirect this stderr to log_file.
3.You also want to see this stderr on terminal when u run the script containing Other_script.
4.Stdout will go to log_file and terminal.
If the above is correct, then try this in your script:
other_script 2>&1|tee log_file
Rgds,
S.C. Fun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2001 06:34 AM
тАО08-22-2001 06:34 AM
Solutionprint -u 2 "whatever"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2001 09:26 AM
тАО08-22-2001 09:26 AM
Re: Echo to StdErr
> 1.The script Other_script will produce stderr.
- Yes, That's bascially my whole question right there, how to make the script produce stderr.
> 2.You need to redirect this stderr to log_file.
- No, I'm already redirecting stdout to log_file. I don't need anything else going to the log_file, but I do want to be able to send other messages to the terminal through the use of stderr.
> 3.You also want to see this stderr on terminal when u run the script containing Other_script.
- Yes, stderr needs to only go to the termial.
> 4.Stdout will go to log_file and terminal.
- No... Stdout and only Stdout will go to the log_file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2001 10:39 AM
тАО08-22-2001 10:39 AM
Re: Echo to StdErr
example, if you have a script.
#/sbin/sh #test.sh
echo "This is a test" >&2
##end of script
then run it as:
./test.sh > log_file
-This is a test- will be appear on the terminal, but will not go to the log_file. Only standard out will go to log_file. Is this what you are asking?
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2001 02:30 PM
тАО08-22-2001 02:30 PM
Re: Echo to StdErr
echo "This is a test" >&2
will still send something to the log file because all your doing is telling stdout to also go to stderr.
The fallowing answered my question and works great. Thanks.
print -u 2 "whatever"