Welcome, guest | Sign In | My Account | Store | Cart

This recipe was designed for remotely receiving bug reports. It was written after participating in a programming contest where feedback was not helpful. The concept presented here is a step towards working with Python remotely. As sys.stderr is replaced in this recipe, so sys.stdin and sys.stdout can also be redirect to an alternate source (such as sockets connected to another computer).

Python, 35 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
================================================================================
stderr_server.py
================================================================================
PORT = 1337

import socket
serv = socket.socket()
serv.bind(('', PORT))
serv.listen(1)
while True:
    data = ''
    recv = ' '
    conn = serv.accept()[0]
    while recv:
        recv = conn.recv(1024)
        if recv:
            data += recv
        else:
            print data
================================================================================
stderr_client.py
================================================================================
SERV = 'eve.dorms.bju.edu'
PORT = 1337

import socket, sys
conn = socket.socket()
conn.connect((SERV, PORT))
sys.stderr = conn.makefile()
================================================================================
test.py
================================================================================
import stderr_client

number = 1 / 0

test.py demonstates the use of the other two scrips. stderr_client.py must be modified to connect to the right SERV and PORT while stderr_server.py must be modified to serve on the correct PORT.

Created by Stephen Chappell on Sat, 18 Mar 2006 (PSF)
Python recipes (4591)
Stephen Chappell's recipes (233)

Required Modules

  • (none specified)

Other Information and Tasks