Solved

redirecting stdout from within ksh script

Posted on 1997-09-04
3
745 Views
Last Modified: 2013-12-26
Is it possible to execute an intruction at the top of a ksh script to redirect any further standard output to a file? I want to avoid having to create another script which calls the main script with redirection.
0
Comment
Question by:yppirt090497
3 Comments
 
LVL 1

Expert Comment

by:onestar
Comment Utility
Can you give a example of what you are looking (a copy of you script)?
0
 

Accepted Solution

by:
aditya070797 earned 25 total points
Comment Utility
Hi,
You can do that by enclosing the code in curly braces
and redirecting the output to a file at the closing of the curly braces.

Here is how you can do just that:

Ex: dummy.sh
---------------------------------------------
#!/bin/sh
# Note: open curly-brace:
{
# Do some shell things..
#....
echo "Done some shell things"
# Do some more silly shell things..
# ...
echo "Done some more silly shell things.."
# Done; close curly brace.
} >dummy.out 2>&1
# The above line should redirect both stdout and stderr
# of the preceding script to a file dummy.out  
---------------------------------------------




0
 

Author Comment

by:yppirt090497
Comment Utility
Tested and it works nicely.

I was also sent another solution which uses 'exec'.

exec 1>foo
exec 2>foo
echo "test redirect"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now