[OT] combine stdout and stderr...
Bill Campbell
linux-sxs at celestial.com
Tue Mar 3 09:52:52 PST 2009
On Tue, Mar 03, 2009, Jorge Almeida wrote:
> ...in C?
>
> #!/bin/bash
> exec 2>&1
> exec someprogram
>
> This executes someprogram with stdout and stderr combined, meaning that
> what is written to fd 2 really goes to fd 1. The shell is spawned just
> to do this merging, and then it is dropped. There must be a way to do it
> in the code of someprogram, but it doesn't seem easy to google for it...
> ...Some pointers, anyone?
In python it's easy:
#!/usr/bin/env python
import sys
sys.stdout = sys.stderr
In C I think ``man dup'' describes how to do this. It's been
years since I did much C, and generally avoided things like this.
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186
In the 20th century, the Soviet Union made the state's role
absolute. In the long run, this made the Soviet economy totally
uncompetitive. This lesson cost us dearly. I am sure nobody wants
to see it repeated. -- Vladimir Putin
More information about the Linux-users
mailing list