0

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.

Riki137
  • 2,076
  • 2
  • 23
  • 26
  • possible duplicate of [Suppressing output of module calling outside library](http://stackoverflow.com/questions/4178614/suppressing-output-of-module-calling-outside-library) – Ignacio Vazquez-Abrams Apr 12 '11 at 14:41
  • 1
    You use `subprocess` or something like that to spawn a new process? If yes, just execute ` >/dev/null 2>&1` and print whatever you want. – khachik Apr 12 '11 at 14:42

2 Answers2

2

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.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
1
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.)

jtniehof
  • 581
  • 3
  • 8