Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How can I Redirect stderr into stdout ?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-02-2009
Member
 
Join Date: Feb 2009
Posts: 15
How can I Redirect stderr into stdout ?
  

Hello, I was just Thinking that If we out of desc , stdin, stdout and stderr could possibly map stderr on stdout Mean what Would be the Result of that ,Hope not Negative , Can You please Tell me How Could we Possibly Redirect Stderr into Stdout , PLease Give Proper Suggestion thanks in Advance

Reply With Quote
  #2  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 115
Re: How can I Redirect stderr into stdout ?

Very simple, just remember:
  • 1 = stdout
  • 2 = stderr

In python, its

unittest

module loves to dump test results to stderr (rather than stdout). In order to pipe the results to

less

, you may need to redirect stderr to stdout:

python eggtest.py 2>&1 | less

To redirect stderr into a file:

python eggtest.py 2> result.txt

To redirect both stdout and stderr into a file:

python eggtest.py &> spam.txt

Hope it Will Help you
Reply With Quote
  #3  
Old 27-02-2009
Member
 
Join Date: Feb 2008
Posts: 1,843
Re: How can I Redirect stderr into stdout ?

For Python?

import sys
sys.stderr = sys.stdout

Unix/Linux?

myscript.py 2>&1
Reply With Quote
  #4  
Old 27-02-2009
Member
 
Join Date: Oct 2005
Posts: 2,387
Re: How can I Redirect stderr into stdout ?

Stderr can run any type of command, be it an executable or a batch file, with any number of arguments. Since the command is run through the shell, the environment variable COMSPEC must be set (it always is). Since the command is a child process of Stderr, Stderr (and the resident part of the shell) remain in memory during the execution of the command. This means that there is less memory available to the command than if it was run directly through the top-level shell. In the case of command.com, that's about 11 kB less.Stderr is a good example application of the frequently misunderstood dup2 system call.Microsoft C 5.1 included a program named errout. Stderr and errout are not equivalent. errout can redirect stdout and stderr to different files; Stderr cannot. Stderr can pipe stderr into another program; errout cannot. errout consumes more command-line real estate (at minimum 4 more characters) and more memory Refer This page it may helpful
Reply With Quote
  #5  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 2,286
Re: How can I Redirect stderr into stdout ?

In csh, you can redirect stdout with ">", or stdout and stderr together with ">&" but there is no direct way to redirect stderr only. The best you can do is

( command >stdout_file ) >&stderr_file

which runs "command" in a subshell; stdout is redirected inside the subshell to stdout_file, and both stdout and stderr from the subshell are redirected to stderr_file, but by this point stdout has already been redirected so only stderr actually winds up in stderr_file. If what you want is to avoid redirecting stdout at all, let sh do it for you.

sh -c 'command 2>stderr_file'
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How can I Redirect stderr into stdout ?"
Thread Thread Starter Forum Replies Last Post
Inter-thread communication with stdout Captain Carrot Software Development 5 12-03-2010 11:34 AM
What is Alexa Redirect Paisley007 Technology & Internet 3 07-08-2009 04:54 PM
[Named Pipe] Redirection of STDIN and STDOUT Shanbaag Software Development 2 24-04-2009 03:53 PM
Redirect dns or iis? The_cobra666 Windows Server Help 4 05-12-2007 05:47 PM


All times are GMT +5.5. The time now is 08:48 PM.