Reputation: 2561
How can i hide the process of installing java (apt-get openjdk-6-jre) when it's runned in python? So i can replace it with "Installing Java..." till it's ready.
Thanks in advance.
Upvotes: 0
Views: 358
Reputation: 414645
Here's an implementation of @khachik's comment:
import os
from subprocess import STDOUT, check_call
check_call(['apt-get', 'install', 'openjdk-6-jre'],
stdout=open(os.devnull,'wb'), stderr=STDOUT)
It raises an exception in case of an error.
Upvotes: 2
Reputation: 601
proc = subprocess.Popen('apt-get install openjdk-6-jre', stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, errors = proc.communicate()
return_Value = proc.returncode
This puts the program output into a string in Python, where you should probably check it for errors. See subprocess docs. (Unlike the redirect to /dev/null, this is cross-platform.)
Upvotes: 1