Python console output gets overwritten in Debian 6
Question: I have a small script in python which automates installation of a few packages
like wget, git, using apt-get in Debian 6 (Python 2.6.6). the script then
installs `pip` and then using `pip`, installs _requests_ and _phpserialize_.
The following is the output got when the script is run:

    
    
    root@ffVMdeb64:~# python test.py 
    Reading package lists... Done
    mkdir: cannot create directory `/usr/local/src/forpip': File exists
    Building dependency tree       
    Reading state information... Done
    git is already the newest version.
    wget is already the newest version.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Reading package lists... Done
    Building dependency tree... 50%
    
    
    Building dependency tree       
    Reading state information... Done
    Requirement already satisfied (use --upgrade to upgrade): phpserialize in /usr/local/lib/python2.6/dist-packages
    Cleaning up...
    Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.6/dist-packages
    Cleaning up...
    git is already the newest version.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    

At the end, there the script takes some input from the user. However, the
`raw_input` statement gets executed while the output for the install process
is still going on and hence gets overwritten. Notice the blank space between 2
blocks of output above - that is where the `raw_input` statement gets printed
and then overwritten.

The relevant parts of the script is as follows:

    
    
    subprocess.call("pip install phpserialize &> /dev/null 2>&1", shell=True)
    subprocess.call("pip install requests &> /dev/null  2>&1", shell=True)
    subprocess.call("apt-get install git -y &> /dev/null 2>&1", shell=True)
    import phpserialize
    import requests
    from phpserialize import serialize
    from phpserialize import unserialize
    
    def checktext():
        text = raw_input("\n\n\nEnter your text:")
        return text
    
    itext = checktext()
    

I tested the exact same script in CentOS 6.3 and 6.4 and it worked as
expected. I guess it has something to do with the `Building dependency tree...
50%` part of `apt-get` but i am not sure.

How can I correct this?


Answer: This might not be the exact solution and I'm pretty sure there'll be a better
solution but i think if you try `sleep` after your last `apt-get` statement,
it might work.

As per your code:

    
    
    import time
    subprocess.call("pip install phpserialize &> /dev/null 2>&1", shell=True)
    subprocess.call("pip install requests &> /dev/null  2>&1", shell=True)
    subprocess.call("apt-get install git -y &> /dev/null 2>&1", shell=True)
    time.sleep(5)
    import phpserialize
    import requests
    from phpserialize import serialize
    from phpserialize import unserialize
    
    def checktext():
        text = raw_input("\n\n\nEnter your text:")
        return text
    
    itext = checktext()
    

That causes the whole `apt-get` to execute first and then moves on to your
`text=...` statment.

Hope this helps

