Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108281
| From | Jim Dodgen <jim@dodgen.us> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | redirecting stdout and stderr to /dev/null |
| Date | 2016-05-07 11:40 -0700 |
| Message-ID | <mailman.460.1462646798.32212.python-list@python.org> (permalink) |
| References | <CAJ2wgcp0HjygmdAw_Q1zJEs=BRWEuDnYRUzQPCcnZEbS0i3uSw@mail.gmail.com> |
I'm new to python but well versed on other languages such as C and Perl
I'm have problems redirecting stdout and stderr to /dev/null in a
program that does a fork and exec. T found this method googling around and
it is
quite elegant compared to to the Perl version.
So to isolate things I made a much shorter test program and it still is not
redirecting. What am I doing wrong?
test program test.py
----------------- cut here -------------------
import sys
import os
f = open(os.devnull, 'w')
sys.stdout = f
sys.stderr = f
os.execl("/bin/ping", "", "-w", "20", "192.168.1.1");
------------------ cut here -------------------
results when run
root@dev:/home/jim# python test.py
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.36 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.00 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=1.01 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=1.16 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=1.02 ms
^C
--- 192.168.1.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 1.002/1.114/1.361/0.136 ms
root@dev:/home/jim#
*Jim Dodgen*
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
redirecting stdout and stderr to /dev/null Jim Dodgen <jim@dodgen.us> - 2016-05-07 11:40 -0700
csiph-web