tags:

views:

28

answers:

0
#!/usr/bin/env python

from subprocess import *

p = Popen(
  args=("java","-jar","jmxterm-1.0-alpha-4-uber.jar"), 
  bufsize=0, 
  stdin=PIPE,
  stderr=PIPE
  )

p.stdin.write("open localhost:12345\n")
x = p.stderr.readline()

This needs a java process listening for a jmx client on port 12345. The script "works": x is correct (when you print it or look at it in pdb).

What's the problem then? When this script terminates, the shell behaves strangely. On Linux and OS-X, typing in the shell isn't visible (although output is), and on windows, the first two characters typed per command are ignored. Executing the terminal "reset" command seems to fix it, but I don't want to inflict this on users of my script.

Removing the last line of the script (accessing p.stderr.readline()) eliminates the problem, but also the script's utility.

I've removed authentication to simplify the example. You'll note that I don't print x, to eliminate writing something nasty to the the shell as a culprit.

Versions: CPython 2.7 on Snow Leopard and various Linuxes; CPython 2.6.3 on Windows 7