Riki137
Riki137

Reputation: 2561

Hide echo from apt-get in python

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

Answers (2)

jfs
jfs

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

jtniehof
jtniehof

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

Related Questions