Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Python script that makes use of the following modules:

import sys, getopt, os, time, subprocess

When I run this script, at some point the output starts 'tabbing' itself.

Expected output:

line1
line2
line3

Output I get:

line 1
          line 2
                    line 3

When the script completes, or I exit it my shell (via SSH) becomes broken. I cannot see what I'm typing, and hitting enter doesn't create a new line but instead just 'tabs' as well (output of hitting enter a few times, then

ps ax | grep [s]sh

, then enter a few more times):

issue Any thoughts or ideas as to what may be causing this and how it can be resolved or debugged?

share|improve this question
    
You can probably fix your shell when this happens by typing reset. As for what is causing it to get messed up, probably your script is printing some kind of control character to the screen. Can you show its output, and the code that causes it? –  Blckknght Oct 19 '12 at 19:19
    
Reset did fix it. I would post the code but it's work related so I cannot. What kind of control character would cause this? I'm not printing anything like that explicitly, but I do call some other commands with subprocess (though the output is directed to os.devnull) –  Rauffle Oct 19 '12 at 19:22
2  
It's caused by one of the subprocesses manipulating the tty settings either by accident (by printing control characters) or on purpose. Use reset or if that doesn't work, then stty sane –  Petesh Oct 19 '12 at 19:26
    
I've isolated the issue to a single 'subprocess.Popen' line that spawns an SSH session that runs some commands in a single line (ie. command1;command2;command3). I've attempted redirecting the outputs to /dev/null but the issue still occurs. I've attempted running the command it spawns manually and I run in to no issues, it only breaks when the command is run under subprocess. Any idea why this would be? It also does NOT break SSH on the first run, but any subsequent run does. 'reset' doesn't appear to fully work either, things are still buggy/laggy until I restart the session itself. –  Rauffle Oct 24 '12 at 20:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.