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.

2
  • possible duplicate of Suppressing output of module calling outside library Commented Apr 12, 2011 at 14:41
  • 1
    You use subprocess or something like that to spawn a new process? If yes, just execute <command_here> >/dev/null 2>&1 and print whatever you want. Commented Apr 12, 2011 at 14:42

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.)

1 Comment

os.devnull is cross-platform.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.