1

My code:

import os

os.system("pip install colorama")

This starts to print the actual command and such, is there a way to execute this without anything being printed. Or even like for example a variable with the response and I can handle it from there? I don't want a massive text, just a simple one saying it was installed etc.

davejohn2s
  • 21
  • 2
  • Do these help?: https://stackoverflow.com/questions/7006238/how-do-i-hide-the-console-when-i-use-os-system-or-subprocess-call, https://stackoverflow.com/questions/33985863/hiding-console-output-produced-by-os-system and https://stackoverflow.com/questions/54931392/python-hide-console-window – The Amateur Coder May 19 '22 at 16:07
  • You can use `subprocess.Popen()` to run the command like this: `import subprocess subprocess.Popen(["cmd", "/k", "pip install colorama"])` This might also help: `subprocess.Popen(["cmd", "/k", "pip install colorama"], shell=True)` – ZiyadCodes May 19 '22 at 16:15

2 Answers2

2

You could probably redirect the output into /dev/null, so you could do something like the following:

import os

os.system(“pip install colorama > /dev/null 2>&1“)

Note that this would also redirect the errors (because of the 2>&1). If you want to keep errors, you should remove that.

ByteAtATime
  • 130
  • 1
  • 8
0

You would probably use echo Off as the first command, then run colorama, then use echo to say whatever final message you want, like this:

import os
os.system("@echo off")
os.system("pip install colorama")
os.system("echo on")
os.system("echo Colorama installed.")