1

I get this message: "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."

In a simple script that does

process = subprocess.Popen(['apt', 'upgrade', '-y'], stdout=subprocess.PIPE)

How can I remove that annoying warning when running apt from python subprocess? I don't mind the rest of the output, I only want to get rid of the warning.

Edit:

I'm iterating though the output so that I can get live output from apt. How can I remove it from there?

with open('test.log', 'w') as f:
        process = subprocess.Popen(['apt', 'upgrade', '-y'],
                                   stdout=subprocess.PIPE,  stderr=subprocess.PIPE)
        for line in iter(process.stdout.readline, ''):
                sys.stdout.write(line)
                f.write(line)

1 Answer 1

1

That message is sent over stderr. I would capture it by piping it, just like you did with stdout:

>>> process = subprocess.Popen(['apt', 'search', 'python'], stdout=subprocess.PIPE,
...                                                         stderr=subprocess.PIPE)
>>> stdout, stderr = process.communicate()
>>> stderr
'\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\n'
Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks for the answer, please see my updated question. I'm still not sure how to exclude that warning yet.
@answerSeeker: Your updated code doesn't produce that message for me.
Ahh thanks!. I thought it'd be the same but the stderr=subprocess.PIPE really fixed it

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.