The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sending stdout and stderr to a file mistermojo Shell Programming and Scripting 2 02-04-2009 02:29 AM
How to redirect stderr and stdout to a file sushantnirwan Shell Programming and Scripting 8 08-28-2008 09:23 AM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 12:24 PM
Redirect stdout & stderr and append to a file Santi Shell Programming and Scripting 2 01-02-2006 07:58 PM
Redirect stdout and stderr zcurtis Shell Programming and Scripting 8 09-02-2002 06:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
islegmar islegmar is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 10
Redirect stdout/stderr to a file globally

Hi

I am not if this is possible: is it possible in bach (or another shell) to redirect GLOBALLY the stdout/stderr channels to a file.

So, if I have a script

script.sh
cmd1
cmd2
cmd3

I want all stdout/stderr goes to a file. I know I can do:

./script.sh 1>file 2>&1

OR

script.sh
cmd1 1>>file 2>>&1
cmd2 1>>file 2>>&1
cmd3 1>>file 2>>&1

but, what I want to do, is something like

script.sh
stdout is now 'file'
stderr is now 'file'
cmd1
cmd2
cmd3

Why do I want to do that? I'm just curious :-)

Thanks a lot

Isi

PS: I guess that must be called 'channel duplication' or something like that
  #2 (permalink)  
Old 04-22-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
exec 1>std.out.file
exec 2>std.err.file 
# other code here ........
exit
  #3 (permalink)  
Old 04-22-2009
islegmar islegmar is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 10
Awesome! :-)

Let's suppose I'm not inside a script, I am in a shell (so, I don't want to execute exit), how can I undo the redirect? Somehing like "exec 1>/dev/tty[n]"? How can I see where is stdout pointing (echo....) ?

Thanks a lot

Isi
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0